diff --git a/src/types/kind.rs b/src/types/kind.rs new file mode 100644 index 0000000..4f47b85 --- /dev/null +++ b/src/types/kind.rs @@ -0,0 +1,28 @@ +use std::fmt; + +#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +pub struct Kind(pub u16); + +impl fmt::Display for Kind { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) + } +} + +impl Kind { + // Some kinds a relay may need to treat differently + pub const SEAL: u16 = 13; + pub const DM_CHAT: u16 = 14; + + pub fn is_replaceable(&self) -> bool { + (10000..20000).contains(&self.0) || self.0 == 0 || self.0 == 3 + } + + pub fn is_ephemeral(&self) -> bool { + (20000..30000).contains(&self.0) + } + + pub fn is_parameterized_replaceable(&self) -> bool { + (30000..40000).contains(&self.0) + } +} diff --git a/src/types/mod.rs b/src/types/mod.rs index 19febd5..03b0ed3 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -1,2 +1,5 @@ mod id; pub use id::Id; + +mod kind; +pub use kind::Kind;