diff options
Diffstat (limited to '')
| -rw-r--r-- | src/primitive/msgid.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/primitive/msgid.rs b/src/primitive/msgid.rs index fb9b6af..27608fe 100644 --- a/src/primitive/msgid.rs +++ b/src/primitive/msgid.rs @@ -1,4 +1,4 @@ -#[derive(Copy, Clone, Debug, std::cmp::PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] #[repr(transparent)] pub struct MsgId( #[cfg(not(feature = "long-message-id"))] pub i32, @@ -24,6 +24,31 @@ impl Deserialize for MsgId { } } +#[cfg(not(feature = "long-message-id"))] +impl From<i32> for MsgId { + fn from(value: i32) -> Self { + Self(value) + } +} + +#[cfg(feature = "long-message-id")] +impl From<i64> for MsgId { + fn from(value: i64) -> Self { + Self(value) + } +} + +impl std::ops::Deref for MsgId { + #[cfg(not(feature = "long-message-id"))] + type Target = i32; + #[cfg(feature = "long-message-id")] + type Target = i64; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + #[cfg(test)] mod tests { use super::*; |
