diff options
author | Alex Auvolat <alex@adnab.me> | 2022-05-31 15:49:10 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2022-05-31 15:49:10 +0200 |
commit | 01d82c14ca61e7c4de1e72c5f94456610464c064 (patch) | |
tree | 20ada5789d449182e18c3a18751ffd0473486614 /src/uidindex.rs | |
parent | d53cf1d220ef08c0b9368cfe91bee7660b7f5a3b (diff) | |
download | aerogramme-01d82c14ca61e7c4de1e72c5f94456610464c064.tar.gz aerogramme-01d82c14ca61e7c4de1e72c5f94456610464c064.zip |
UUID generator; import kannader smtp server
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)) - } -} |