diff options
| author | 2025-01-30 23:21:10 -0600 | |
|---|---|---|
| committer | 2025-01-30 23:21:10 -0600 | |
| commit | eb75f8512cddac27fb1e0a8aa678ba058862568d (patch) | |
| tree | 9fcfee3089495f6eccf80bf288a14d4586eb6540 /src/auth/types | |
| parent | non-working: auth (diff) | |
user auth
Diffstat (limited to 'src/auth/types')
| -rw-r--r-- | src/auth/types/property_map.rs | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/auth/types/property_map.rs b/src/auth/types/property_map.rs new file mode 100644 index 0000000..ff67416 --- /dev/null +++ b/src/auth/types/property_map.rs @@ -0,0 +1,50 @@ +use std::fmt::Formatter;
+use multimap::MultiMap;
+use serde::de::{SeqAccess, Visitor};
+use serde::{Deserializer, Serializer};
+use serde::ser::SerializeSeq;
+use crate::auth::Property;
+
+pub type PropertyMap = MultiMap<String, Property>;
+
+pub fn serialize<S>(value: &PropertyMap, serializer: S) -> Result<S::Ok, S::Error>
+where
+ S: Serializer
+{
+ let mut seq = serializer.serialize_seq(Some(value.keys().len()))?;
+
+ for (_, prop) in value.flat_iter() {
+ seq.serialize_element(prop)?;
+ }
+
+ seq.end()
+}
+
+pub fn deserialize<'de, D>(deserializer: D) -> Result<PropertyMap, D::Error>
+where
+ D: Deserializer<'de>
+{
+ struct PropertyMapVisitor;
+
+ impl<'de> Visitor<'de> for PropertyMapVisitor {
+ type Value = PropertyMap;
+
+ fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result {
+ formatter.write_str("a property map")
+ }
+
+ fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
+ where
+ A: SeqAccess<'de>,
+ {
+ let mut map = MultiMap::new() as PropertyMap;
+ while let Some(prop) = seq.next_element::<Property>()? {
+ map.insert(prop.name.clone(), prop);
+ }
+
+ Ok(map)
+ }
+ }
+
+ deserializer.deserialize_seq(PropertyMapVisitor)
+}
|
