relay_base_schema/
organization.rsuse serde::{Deserialize, Serialize};
#[derive(Copy, Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub struct OrganizationId(u64);
impl OrganizationId {
#[inline]
pub fn new(id: u64) -> Self {
Self(id)
}
pub fn value(self) -> u64 {
self.0
}
}
impl std::fmt::Display for OrganizationId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.value())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_deserialize() {
let json = r#"[42]"#;
let ids: Vec<OrganizationId> =
serde_json::from_str(json).expect("deserialize organization ids");
assert_eq!(ids, vec![OrganizationId::new(42)]);
}
#[test]
fn test_serialize() {
let ids = vec![OrganizationId::new(42)];
let json = serde_json::to_string(&ids).expect("serialize organization ids");
assert_eq!(json, r#"[42]"#);
}
}