diff options
Diffstat (limited to 'src/uidindex.rs')
-rw-r--r-- | src/uidindex.rs | 36 |
1 files changed, 2 insertions, 34 deletions
diff --git a/src/uidindex.rs b/src/uidindex.rs index 1e30190..ecd52ff 100644 --- a/src/uidindex.rs +++ b/src/uidindex.rs @@ -1,17 +1,12 @@ use im::OrdMap; -use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer}; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; use crate::bayou::*; +use crate::mail_uuid::MailUuid; type ImapUid = u32; type ImapUidvalidity = u32; -/// A Mail UUID is composed of two components: -/// - a process identifier, 128 bits -/// - a sequence number, 64 bits -#[derive(Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Debug)] -pub struct MailUuid(pub [u8; 24]); - #[derive(Clone)] pub struct UidIndex { pub mail_uid: OrdMap<MailUuid, ImapUid>, @@ -176,30 +171,3 @@ impl Serialize for UidIndex { val.serialize(serializer) } } - -impl<'de> Deserialize<'de> for MailUuid { - fn deserialize<D>(d: D) -> Result<Self, D::Error> - where - D: Deserializer<'de>, - { - let v = String::deserialize(d)?; - let bytes = hex::decode(v).map_err(|_| D::Error::custom("invalid hex"))?; - - if bytes.len() != 24 { - return Err(D::Error::custom("bad length")); - } - - let mut tmp = [0u8; 24]; - tmp[..].copy_from_slice(&bytes); - Ok(Self(tmp)) - } -} - -impl Serialize for MailUuid { - fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> - where - S: Serializer, - { - serializer.serialize_str(&hex::encode(self.0)) - } -} |