diff options
Diffstat (limited to 'src/primitive')
| -rw-r--r-- | src/primitive/bufferid.rs | 16 | ||||
| -rw-r--r-- | src/primitive/msgid.rs | 27 | ||||
| -rw-r--r-- | src/primitive/variant.rs | 4 |
3 files changed, 43 insertions, 4 deletions
diff --git a/src/primitive/bufferid.rs b/src/primitive/bufferid.rs index 25cc029..4be867d 100644 --- a/src/primitive/bufferid.rs +++ b/src/primitive/bufferid.rs @@ -1,4 +1,4 @@ -#[derive(Copy, Clone, Debug, std::cmp::PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(transparent)] pub struct BufferId(pub i32); @@ -17,6 +17,20 @@ impl Deserialize for BufferId { } } +impl From<i32> for BufferId { + fn from(value: i32) -> Self { + BufferId(value) + } +} + +impl std::ops::Deref for BufferId { + type Target = i32; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + #[cfg(test)] mod tests { use super::*; 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::*; diff --git a/src/primitive/variant.rs b/src/primitive/variant.rs index 340d908..a7ff8ca 100644 --- a/src/primitive/variant.rs +++ b/src/primitive/variant.rs @@ -288,7 +288,7 @@ impl Serialize for Variant { impl Deserialize for Variant { fn parse(b: &[u8]) -> Result<(usize, Self), ProtocolError> { - trace!("trying to parse variant with bytes: {:?}", b); + trace!("trying to parse variant with bytes: {:x?}", b); let (_, qtype) = i32::parse(&b[0..4])?; let qtype = qtype as u32; @@ -805,7 +805,7 @@ mod tests { #[test] fn bufferid_deserialize() { let test_bytes = vec![ - 0, 0, 0, 127, 0, 0, 0, 0, 8, 66, 117, 102, 102, 101, 114, 73, 100, 0, 0, 0, 1 + 0, 0, 0, 127, 0, 0, 0, 0, 8, 66, 117, 102, 102, 101, 114, 73, 100, 0, 0, 0, 1, ]; assert_eq!( (test_bytes.len(), Variant::BufferId(BufferId(1))), |
