diff --git a/src/address/envelope.rs b/src/address/envelope.rs index 65fb090..3a4aae1 100644 --- a/src/address/envelope.rs +++ b/src/address/envelope.rs @@ -14,11 +14,71 @@ pub struct Envelope { /// The envelope recipient's addresses /// /// This can not be empty. + #[cfg_attr( + feature = "serde", + serde(deserialize_with = "serde_forward_path::deserialize") + )] forward_path: Vec
, /// The envelope sender address reverse_path: Option, } +/// just like the default implementation to deserialize `Vec` but it +/// forbids **de**serializing empty lists +#[cfg(feature = "serde")] +mod serde_forward_path { + use super::Address; + /// dummy type required for serde + /// see example: https://serde.rs/deserialize-map.html + struct CustomVisitor; + impl<'de> serde::de::Visitor<'de> for CustomVisitor { + type Value = Vec; + + fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter.write_str("a non-empty list of recipient addresses") + } + + fn visit_seq