relay_base_schema/
organization.rs

1//! Contains [`OrganizationId`] which is the ID of a Sentry organization and is currently a
2//! a wrapper over `u64`.
3
4use serde::{Deserialize, Serialize};
5
6/// The unique identifier of a Sentry organization.
7#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
8pub struct OrganizationId(u64);
9
10impl OrganizationId {
11    /// Creates a new organization ID from its numeric value
12    #[inline]
13    pub fn new(id: u64) -> Self {
14        Self(id)
15    }
16
17    /// Returns the numeric value of the organization ID.
18    pub fn value(self) -> u64 {
19        self.0
20    }
21}
22
23impl std::fmt::Display for OrganizationId {
24    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25        write!(f, "{}", self.value())
26    }
27}
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32
33    #[test]
34    fn test_deserialize() {
35        let json = r#"[42]"#;
36        let ids: Vec<OrganizationId> =
37            serde_json::from_str(json).expect("deserialize organization ids");
38        assert_eq!(ids, vec![OrganizationId::new(42)]);
39    }
40
41    #[test]
42    fn test_serialize() {
43        let ids = vec![OrganizationId::new(42)];
44        let json = serde_json::to_string(&ids).expect("serialize organization ids");
45        assert_eq!(json, r#"[42]"#);
46    }
47}