|
@@ -0,0 +1,576 @@
|
|
|
+use microrm::prelude::*;
|
|
|
+
|
|
|
+use crate::schema;
|
|
|
+
|
|
|
+use super::Config;
|
|
|
+
|
|
|
+struct ValueToStringSerializer { }
|
|
|
+
|
|
|
+impl<'l> serde::Serializer for &'l ValueToStringSerializer {
|
|
|
+ type Ok = Option<String>;
|
|
|
+ type Error = ConfigError;
|
|
|
+
|
|
|
+ type SerializeSeq = serde::ser::Impossible<Self::Ok, Self::Error>;
|
|
|
+ type SerializeMap = serde::ser::Impossible<Self::Ok, Self::Error>;
|
|
|
+ type SerializeTuple = serde::ser::Impossible<Self::Ok, Self::Error>;
|
|
|
+ type SerializeStruct = serde::ser::Impossible<Self::Ok, Self::Error>;
|
|
|
+ type SerializeTupleStruct = serde::ser::Impossible<Self::Ok, Self::Error>;
|
|
|
+ type SerializeTupleVariant = serde::ser::Impossible<Self::Ok, Self::Error>;
|
|
|
+ type SerializeStructVariant = serde::ser::Impossible<Self::Ok, Self::Error>;
|
|
|
+
|
|
|
+ fn serialize_bool(self, v: bool) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+
|
|
|
+ fn serialize_i8(self, v: i8) -> Result<Self::Ok, Self::Error> {
|
|
|
+ self.serialize_i64(v as i64)
|
|
|
+ }
|
|
|
+ fn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error> {
|
|
|
+ self.serialize_i64(v as i64)
|
|
|
+ }
|
|
|
+ fn serialize_i32(self, v: i32) -> Result<Self::Ok, Self::Error> {
|
|
|
+ self.serialize_i64(v as i64)
|
|
|
+ }
|
|
|
+ fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error> {
|
|
|
+ Ok(Some(v.to_string()))
|
|
|
+ }
|
|
|
+ fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+
|
|
|
+ fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error> {
|
|
|
+ self.serialize_u64(v as u64)
|
|
|
+ }
|
|
|
+ fn serialize_u16(self, v: u16) -> Result<Self::Ok, Self::Error> {
|
|
|
+ self.serialize_u64(v as u64)
|
|
|
+ }
|
|
|
+ fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error> {
|
|
|
+ self.serialize_u64(v as u64)
|
|
|
+ }
|
|
|
+ fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error> {
|
|
|
+ Ok(Some(v.to_string()))
|
|
|
+ }
|
|
|
+ fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+
|
|
|
+ fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+ fn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+
|
|
|
+ fn serialize_char(self, v: char) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+
|
|
|
+ fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+
|
|
|
+ fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error> {
|
|
|
+ Ok(Some(v.into()))
|
|
|
+ }
|
|
|
+
|
|
|
+ fn serialize_none(self) -> Result<Self::Ok, Self::Error> { Ok(None) }
|
|
|
+
|
|
|
+ fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
|
|
+ where
|
|
|
+ T: serde::Serialize {
|
|
|
+
|
|
|
+ value.serialize(self)
|
|
|
+ }
|
|
|
+
|
|
|
+ fn serialize_unit(self) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+
|
|
|
+ fn serialize_seq(self, _len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> { unreachable!() }
|
|
|
+ fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> { unreachable!() }
|
|
|
+ fn serialize_tuple(self, _len: usize) -> Result<Self::SerializeTuple, Self::Error> { unreachable!() }
|
|
|
+ fn serialize_struct(
|
|
|
+ self,
|
|
|
+ _name: &'static str,
|
|
|
+ _len: usize,
|
|
|
+ ) -> Result<Self::SerializeStruct, Self::Error> { unreachable!() }
|
|
|
+
|
|
|
+ fn serialize_unit_struct(self, name: &'static str) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+
|
|
|
+ fn serialize_unit_variant(
|
|
|
+ self,
|
|
|
+ name: &'static str,
|
|
|
+ variant_index: u32,
|
|
|
+ variant: &'static str,
|
|
|
+ ) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+
|
|
|
+ fn serialize_tuple_struct(
|
|
|
+ self,
|
|
|
+ name: &'static str,
|
|
|
+ len: usize,
|
|
|
+ ) -> Result<Self::SerializeTupleStruct, Self::Error> { unreachable!() }
|
|
|
+
|
|
|
+ fn serialize_tuple_variant(
|
|
|
+ self,
|
|
|
+ name: &'static str,
|
|
|
+ variant_index: u32,
|
|
|
+ variant: &'static str,
|
|
|
+ len: usize,
|
|
|
+ ) -> Result<Self::SerializeTupleVariant, Self::Error> {
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn serialize_newtype_struct<T: ?Sized>(
|
|
|
+ self,
|
|
|
+ name: &'static str,
|
|
|
+ value: &T,
|
|
|
+ ) -> Result<Self::Ok, Self::Error>
|
|
|
+ where
|
|
|
+ T: serde::Serialize {
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn serialize_struct_variant(
|
|
|
+ self,
|
|
|
+ name: &'static str,
|
|
|
+ variant_index: u32,
|
|
|
+ variant: &'static str,
|
|
|
+ len: usize,
|
|
|
+ ) -> Result<Self::SerializeStructVariant, Self::Error> {
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn serialize_newtype_variant<T: ?Sized>(
|
|
|
+ self,
|
|
|
+ name: &'static str,
|
|
|
+ variant_index: u32,
|
|
|
+ variant: &'static str,
|
|
|
+ value: &T,
|
|
|
+ ) -> Result<Self::Ok, Self::Error>
|
|
|
+ where
|
|
|
+ T: serde::Serialize {
|
|
|
+
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+pub struct ConfigSerializer<'r, 's, 'l> {
|
|
|
+ pub config: &'r Config,
|
|
|
+ pub qi: &'s microrm::QueryInterface<'l>,
|
|
|
+ pub prefix: String,
|
|
|
+}
|
|
|
+
|
|
|
+impl<'r, 's, 'l> ConfigSerializer<'r, 's, 'l> {
|
|
|
+ fn update(&self, key: &str, value: String) {
|
|
|
+ self.qi.delete().by(schema::PersistentConfig::Key, key).exec().expect("couldn't update config");
|
|
|
+ self.qi.add(&schema::PersistentConfig {
|
|
|
+ key: key.into(),
|
|
|
+ value
|
|
|
+ }).expect("couldn't update config");
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl <'r, 's, 'l> serde::ser::SerializeStruct for ConfigSerializer<'r, 's, 'l> {
|
|
|
+ type Ok = ();
|
|
|
+ type Error = ConfigError;
|
|
|
+
|
|
|
+ fn serialize_field<T: ?Sized>(
|
|
|
+ &mut self,
|
|
|
+ key: &'static str,
|
|
|
+ value: &T,
|
|
|
+ ) -> Result<(), Self::Error>
|
|
|
+ where
|
|
|
+ T: serde::Serialize {
|
|
|
+
|
|
|
+ let key = format!("{}{}", self.prefix, key);
|
|
|
+
|
|
|
+
|
|
|
+ let value = value.serialize(&ValueToStringSerializer {})?;
|
|
|
+ if let Some(value) = value {
|
|
|
+ log::trace!("saving config {} = {}", key, value);
|
|
|
+ self.update(key.as_str(), value);
|
|
|
+ }
|
|
|
+
|
|
|
+ Ok(())
|
|
|
+ }
|
|
|
+
|
|
|
+ fn end(self) -> Result<Self::Ok, Self::Error> {
|
|
|
+ Ok(())
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl<'r, 's, 'l> serde::Serializer for &'r ConfigSerializer<'r, 's, 'l> {
|
|
|
+ type Ok = ();
|
|
|
+ type Error = ConfigError;
|
|
|
+
|
|
|
+ type SerializeSeq = serde::ser::Impossible<Self::Ok, Self::Error>;
|
|
|
+ type SerializeMap = serde::ser::Impossible<Self::Ok, Self::Error>;
|
|
|
+ type SerializeTuple = serde::ser::Impossible<Self::Ok, Self::Error>;
|
|
|
+ type SerializeStruct = ConfigSerializer<'r, 's, 'l>;
|
|
|
+ type SerializeTupleStruct = serde::ser::Impossible<Self::Ok, Self::Error>;
|
|
|
+ type SerializeTupleVariant = serde::ser::Impossible<Self::Ok, Self::Error>;
|
|
|
+ type SerializeStructVariant = serde::ser::Impossible<Self::Ok, Self::Error>;
|
|
|
+
|
|
|
+ fn serialize_bool(self, v: bool) -> Result<Self::Ok, Self::Error> {
|
|
|
+ unreachable!()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn serialize_i8(self, v: i8) -> Result<Self::Ok, Self::Error> {
|
|
|
+ self.serialize_i64(v as i64)
|
|
|
+ }
|
|
|
+ fn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error> {
|
|
|
+ self.serialize_i64(v as i64)
|
|
|
+ }
|
|
|
+ fn serialize_i32(self, v: i32) -> Result<Self::Ok, Self::Error> {
|
|
|
+ self.serialize_i64(v as i64)
|
|
|
+ }
|
|
|
+ fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error> {
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
+ fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+
|
|
|
+ fn serialize_u8(self, v: u8) -> Result<Self::Ok, Self::Error> {
|
|
|
+ self.serialize_u64(v as u64)
|
|
|
+ }
|
|
|
+ fn serialize_u16(self, v: u16) -> Result<Self::Ok, Self::Error> {
|
|
|
+ self.serialize_u64(v as u64)
|
|
|
+ }
|
|
|
+ fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error> {
|
|
|
+ self.serialize_u64(v as u64)
|
|
|
+ }
|
|
|
+ fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error> {
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
+ fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+
|
|
|
+ fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+ fn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+
|
|
|
+ fn serialize_char(self, v: char) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+
|
|
|
+ fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error> {
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn serialize_str(self, v: &str) -> Result<Self::Ok, Self::Error> {
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn serialize_none(self) -> Result<Self::Ok, Self::Error> {
|
|
|
+ Ok(())
|
|
|
+ }
|
|
|
+
|
|
|
+ fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
|
|
+ where
|
|
|
+ T: serde::Serialize {
|
|
|
+
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn serialize_unit(self) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+
|
|
|
+ fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Self::Error> { todo!() }
|
|
|
+ fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> { todo!() }
|
|
|
+ fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, Self::Error> { todo!() }
|
|
|
+ fn serialize_struct(
|
|
|
+ self,
|
|
|
+ name: &'static str,
|
|
|
+ _len: usize,
|
|
|
+ ) -> Result<Self::SerializeStruct, Self::Error> {
|
|
|
+ log::trace!("name: {name}");
|
|
|
+
|
|
|
+ let new_prefix =
|
|
|
+ // are we at the root?
|
|
|
+ if name == "Config" {
|
|
|
+ String::new()
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ format!("{}{}.", self.prefix, name)
|
|
|
+ };
|
|
|
+
|
|
|
+ let subser = ConfigSerializer {
|
|
|
+ config: self.config,
|
|
|
+ qi: self.qi,
|
|
|
+ prefix: new_prefix,
|
|
|
+ };
|
|
|
+
|
|
|
+ Ok(subser)
|
|
|
+ }
|
|
|
+
|
|
|
+ fn serialize_unit_struct(self, name: &'static str) -> Result<Self::Ok, Self::Error> {
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn serialize_unit_variant(
|
|
|
+ self,
|
|
|
+ name: &'static str,
|
|
|
+ variant_index: u32,
|
|
|
+ variant: &'static str,
|
|
|
+ ) -> Result<Self::Ok, Self::Error> {
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn serialize_tuple_struct(
|
|
|
+ self,
|
|
|
+ name: &'static str,
|
|
|
+ len: usize,
|
|
|
+ ) -> Result<Self::SerializeTupleStruct, Self::Error> {
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn serialize_tuple_variant(
|
|
|
+ self,
|
|
|
+ name: &'static str,
|
|
|
+ variant_index: u32,
|
|
|
+ variant: &'static str,
|
|
|
+ len: usize,
|
|
|
+ ) -> Result<Self::SerializeTupleVariant, Self::Error> {
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn serialize_newtype_struct<T: ?Sized>(
|
|
|
+ self,
|
|
|
+ name: &'static str,
|
|
|
+ value: &T,
|
|
|
+ ) -> Result<Self::Ok, Self::Error>
|
|
|
+ where
|
|
|
+ T: serde::Serialize {
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn serialize_struct_variant(
|
|
|
+ self,
|
|
|
+ name: &'static str,
|
|
|
+ variant_index: u32,
|
|
|
+ variant: &'static str,
|
|
|
+ len: usize,
|
|
|
+ ) -> Result<Self::SerializeStructVariant, Self::Error> {
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn serialize_newtype_variant<T: ?Sized>(
|
|
|
+ self,
|
|
|
+ name: &'static str,
|
|
|
+ variant_index: u32,
|
|
|
+ variant: &'static str,
|
|
|
+ value: &T,
|
|
|
+ ) -> Result<Self::Ok, Self::Error>
|
|
|
+ where
|
|
|
+ T: serde::Serialize {
|
|
|
+
|
|
|
+ todo!()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+pub struct ConfigDeserializer<'de> {
|
|
|
+ pub config_map: &'de std::collections::HashMap<String, String>,
|
|
|
+ pub prefix: String,
|
|
|
+}
|
|
|
+
|
|
|
+#[derive(Debug)]
|
|
|
+pub enum ConfigError {
|
|
|
+ Missing(String),
|
|
|
+ InvalidType(String),
|
|
|
+ CustomError(String),
|
|
|
+}
|
|
|
+
|
|
|
+impl std::fmt::Display for ConfigError {
|
|
|
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
+ match self {
|
|
|
+ Self::Missing(what) => f.write_fmt(format_args!(
|
|
|
+ "Missing required config entry: {}",
|
|
|
+ what.as_str()
|
|
|
+ )),
|
|
|
+ Self::InvalidType(what) => f.write_fmt(format_args!(
|
|
|
+ "Could not parse config entry '{}'",
|
|
|
+ what.as_str()
|
|
|
+ )),
|
|
|
+ Self::CustomError(what) => {
|
|
|
+ f.write_fmt(format_args!("Custom error '{}'", what.as_str()))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl std::error::Error for ConfigError {}
|
|
|
+
|
|
|
+impl serde::ser::Error for ConfigError {
|
|
|
+ fn custom<T>(msg: T) -> Self
|
|
|
+ where
|
|
|
+ T: std::fmt::Display,
|
|
|
+ {
|
|
|
+ Self::CustomError(msg.to_string())
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl serde::de::Error for ConfigError {
|
|
|
+ fn custom<T>(msg: T) -> Self
|
|
|
+ where
|
|
|
+ T: std::fmt::Display,
|
|
|
+ {
|
|
|
+ Self::CustomError(msg.to_string())
|
|
|
+ }
|
|
|
+
|
|
|
+ fn invalid_type(_unexp: serde::de::Unexpected, _exp: &dyn serde::de::Expected) -> Self {
|
|
|
+ Self::InvalidType("".into())
|
|
|
+ }
|
|
|
+
|
|
|
+ fn missing_field(field: &'static str) -> Self {
|
|
|
+ Self::Missing(field.into())
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+impl<'de> serde::Deserializer<'de> for &'de mut ConfigDeserializer<'de> {
|
|
|
+ type Error = ConfigError;
|
|
|
+
|
|
|
+ fn deserialize_any<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
+ where
|
|
|
+ V: serde::de::Visitor<'de>,
|
|
|
+ {
|
|
|
+ unreachable!("deserialize_any needs context")
|
|
|
+ }
|
|
|
+
|
|
|
+ fn deserialize_struct<V>(
|
|
|
+ self,
|
|
|
+ _name: &'static str,
|
|
|
+ _fields: &'static [&'static str],
|
|
|
+ visitor: V,
|
|
|
+ ) -> Result<V::Value, Self::Error>
|
|
|
+ where
|
|
|
+ V: serde::de::Visitor<'de>,
|
|
|
+ {
|
|
|
+ self.deserialize_map(visitor)
|
|
|
+ }
|
|
|
+
|
|
|
+ fn deserialize_seq<V>(self, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
+ where
|
|
|
+ V: serde::de::Visitor<'de>,
|
|
|
+ {
|
|
|
+ todo!("deserialize_seq")
|
|
|
+ }
|
|
|
+
|
|
|
+ fn deserialize_map<V>(mut self, visitor: V) -> Result<V::Value, Self::Error>
|
|
|
+ where
|
|
|
+ V: serde::de::Visitor<'de>,
|
|
|
+ {
|
|
|
+ let mut map_access = ConfigDeserializerIterator {
|
|
|
+ it: self
|
|
|
+ .config_map
|
|
|
+ .iter()
|
|
|
+ .filter(|e| {
|
|
|
+ e.0.starts_with(&self.prefix) && !e.0[self.prefix.len()..].contains(".")
|
|
|
+ })
|
|
|
+ .peekable(),
|
|
|
+ };
|
|
|
+
|
|
|
+ visitor.visit_map(&mut map_access)
|
|
|
+ }
|
|
|
+
|
|
|
+ fn deserialize_enum<V>(
|
|
|
+ self,
|
|
|
+ _name: &'static str,
|
|
|
+ _variants: &'static [&'static str],
|
|
|
+ _visitor: V,
|
|
|
+ ) -> Result<V::Value, Self::Error>
|
|
|
+ where
|
|
|
+ V: serde::de::Visitor<'de>,
|
|
|
+ {
|
|
|
+ todo!("deserialize_enum")
|
|
|
+ }
|
|
|
+
|
|
|
+ fn deserialize_tuple<V>(self, _len: usize, _visitor: V) -> Result<V::Value, Self::Error>
|
|
|
+ where
|
|
|
+ V: serde::de::Visitor<'de>,
|
|
|
+ {
|
|
|
+ todo!("deserialize_tuple")
|
|
|
+ }
|
|
|
+
|
|
|
+ fn deserialize_tuple_struct<V>(
|
|
|
+ self,
|
|
|
+ _name: &'static str,
|
|
|
+ _len: usize,
|
|
|
+ _visitor: V,
|
|
|
+ ) -> Result<V::Value, Self::Error>
|
|
|
+ where
|
|
|
+ V: serde::de::Visitor<'de>,
|
|
|
+ {
|
|
|
+ todo!("deserialize_tuple_struct")
|
|
|
+ }
|
|
|
+
|
|
|
+ serde::forward_to_deserialize_any!(
|
|
|
+ i8 u8 i16 u16 i32 u32 i64 u64 i128 u128 str string bytes
|
|
|
+ bool f32 f64 char byte_buf option unit unit_struct
|
|
|
+ newtype_struct identifier ignored_any
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+struct AtomicForwarder<'de> {
|
|
|
+ to_fwd: &'de str,
|
|
|
+}
|
|
|
+
|
|
|
+impl<'de> serde::Deserializer<'de> for AtomicForwarder<'de> {
|
|
|
+ type Error = ConfigError;
|
|
|
+ fn deserialize_any<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
|
|
+ where
|
|
|
+ V: serde::de::Visitor<'de>,
|
|
|
+ {
|
|
|
+ unreachable!()
|
|
|
+ }
|
|
|
+
|
|
|
+ fn deserialize_u64<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
|
|
+ where
|
|
|
+ V: serde::de::Visitor<'de> {
|
|
|
+
|
|
|
+ visitor.visit_u64(self.to_fwd.parse().map_err(|_| ConfigError::InvalidType(String::new()))?)
|
|
|
+ }
|
|
|
+
|
|
|
+ fn deserialize_str<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
|
|
+ where
|
|
|
+ V: serde::de::Visitor<'de>,
|
|
|
+ {
|
|
|
+ visitor.visit_str(self.to_fwd)
|
|
|
+ }
|
|
|
+
|
|
|
+ fn deserialize_string<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
|
|
+ where
|
|
|
+ V: serde::de::Visitor<'de>,
|
|
|
+ {
|
|
|
+ visitor.visit_str(self.to_fwd)
|
|
|
+ }
|
|
|
+
|
|
|
+ fn deserialize_identifier<V>(self, visitor: V) -> Result<V::Value, Self::Error>
|
|
|
+ where
|
|
|
+ V: serde::de::Visitor<'de>,
|
|
|
+ {
|
|
|
+ visitor.visit_str(self.to_fwd)
|
|
|
+ }
|
|
|
+
|
|
|
+ serde::forward_to_deserialize_any!(
|
|
|
+ i8 u8 i16 u16 i32 u32 i64 i128 u128 bytes
|
|
|
+ bool f32 f64 char byte_buf unit unit_struct option
|
|
|
+ newtype_struct ignored_any struct tuple tuple_struct
|
|
|
+ seq map enum
|
|
|
+ );
|
|
|
+}
|
|
|
+
|
|
|
+struct ConfigDeserializerIterator<'de, I: Iterator<Item = (&'de String, &'de String)>> {
|
|
|
+ it: std::iter::Peekable<I>,
|
|
|
+}
|
|
|
+
|
|
|
+impl<'de, I: Iterator<Item = (&'de String, &'de String)>> serde::de::MapAccess<'de>
|
|
|
+ for ConfigDeserializerIterator<'de, I>
|
|
|
+{
|
|
|
+ type Error = ConfigError;
|
|
|
+
|
|
|
+ fn next_key_seed<K>(&mut self, seed: K) -> Result<Option<K::Value>, Self::Error>
|
|
|
+ where
|
|
|
+ K: serde::de::DeserializeSeed<'de>,
|
|
|
+ {
|
|
|
+ if let Some(e) = self.it.peek() {
|
|
|
+ let de = AtomicForwarder {
|
|
|
+ to_fwd: e.0.as_str(),
|
|
|
+ };
|
|
|
+ Ok(seed.deserialize(de).ok())
|
|
|
+ } else {
|
|
|
+ Ok(None)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fn next_value_seed<V>(&mut self, seed: V) -> Result<V::Value, Self::Error>
|
|
|
+ where
|
|
|
+ V: serde::de::DeserializeSeed<'de>,
|
|
|
+ {
|
|
|
+ let value = self.it.next().unwrap();
|
|
|
+
|
|
|
+ let de = AtomicForwarder {
|
|
|
+ to_fwd: value.1.as_str(),
|
|
|
+ };
|
|
|
+
|
|
|
+ seed.deserialize(de)
|
|
|
+ .map_err(|e| ConfigError::InvalidType(e.to_string()))
|
|
|
+ }
|
|
|
+}
|