|
@@ -4,7 +4,7 @@ use crate::schema;
|
|
|
|
|
|
use super::Config;
|
|
|
|
|
|
-struct ValueToStringSerializer { }
|
|
|
+struct ValueToStringSerializer {}
|
|
|
|
|
|
impl<'l> serde::Serializer for &'l ValueToStringSerializer {
|
|
|
type Ok = Option<String>;
|
|
@@ -18,7 +18,9 @@ impl<'l> serde::Serializer for &'l ValueToStringSerializer {
|
|
|
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_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)
|
|
@@ -32,7 +34,9 @@ impl<'l> serde::Serializer for &'l ValueToStringSerializer {
|
|
|
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_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)
|
|
@@ -46,53 +50,81 @@ impl<'l> serde::Serializer for &'l ValueToStringSerializer {
|
|
|
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_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_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_char(self, v: char) -> Result<Self::Ok, Self::Error> {
|
|
|
+ unreachable!()
|
|
|
+ }
|
|
|
|
|
|
- fn serialize_bytes(self, v: &[u8]) -> 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_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 {
|
|
|
-
|
|
|
+ T: serde::Serialize,
|
|
|
+ {
|
|
|
value.serialize(self)
|
|
|
}
|
|
|
|
|
|
- fn serialize_unit(self) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+ 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_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!() }
|
|
|
+ ) -> Result<Self::SerializeStruct, Self::Error> {
|
|
|
+ unreachable!()
|
|
|
+ }
|
|
|
|
|
|
- fn serialize_unit_struct(self, name: &'static str) -> Result<Self::Ok, 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!() }
|
|
|
+ ) -> Result<Self::Ok, Self::Error> {
|
|
|
+ unreachable!()
|
|
|
+ }
|
|
|
|
|
|
fn serialize_tuple_struct(
|
|
|
self,
|
|
|
name: &'static str,
|
|
|
len: usize,
|
|
|
- ) -> Result<Self::SerializeTupleStruct, Self::Error> { unreachable!() }
|
|
|
+ ) -> Result<Self::SerializeTupleStruct, Self::Error> {
|
|
|
+ unreachable!()
|
|
|
+ }
|
|
|
|
|
|
fn serialize_tuple_variant(
|
|
|
self,
|
|
@@ -110,7 +142,8 @@ impl<'l> serde::Serializer for &'l ValueToStringSerializer {
|
|
|
value: &T,
|
|
|
) -> Result<Self::Ok, Self::Error>
|
|
|
where
|
|
|
- T: serde::Serialize {
|
|
|
+ T: serde::Serialize,
|
|
|
+ {
|
|
|
todo!()
|
|
|
}
|
|
|
|
|
@@ -132,8 +165,8 @@ impl<'l> serde::Serializer for &'l ValueToStringSerializer {
|
|
|
value: &T,
|
|
|
) -> Result<Self::Ok, Self::Error>
|
|
|
where
|
|
|
- T: serde::Serialize {
|
|
|
-
|
|
|
+ T: serde::Serialize,
|
|
|
+ {
|
|
|
todo!()
|
|
|
}
|
|
|
}
|
|
@@ -146,15 +179,21 @@ pub struct ConfigSerializer<'r, 's, 'l> {
|
|
|
|
|
|
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");
|
|
|
+ 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> {
|
|
|
+impl<'r, 's, 'l> serde::ser::SerializeStruct for ConfigSerializer<'r, 's, 'l> {
|
|
|
type Ok = ();
|
|
|
type Error = ConfigError;
|
|
|
|
|
@@ -164,11 +203,10 @@ impl <'r, 's, 'l> serde::ser::SerializeStruct for ConfigSerializer<'r, 's, 'l> {
|
|
|
value: &T,
|
|
|
) -> Result<(), Self::Error>
|
|
|
where
|
|
|
- T: serde::Serialize {
|
|
|
-
|
|
|
+ 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);
|
|
@@ -211,7 +249,9 @@ impl<'r, 's, 'l> serde::Serializer for &'r ConfigSerializer<'r, 's, 'l> {
|
|
|
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_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)
|
|
@@ -225,12 +265,20 @@ impl<'r, 's, 'l> serde::Serializer for &'r ConfigSerializer<'r, 's, 'l> {
|
|
|
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_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_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_char(self, v: char) -> Result<Self::Ok, Self::Error> {
|
|
|
+ unreachable!()
|
|
|
+ }
|
|
|
|
|
|
fn serialize_bytes(self, v: &[u8]) -> Result<Self::Ok, Self::Error> {
|
|
|
todo!()
|
|
@@ -246,16 +294,24 @@ impl<'r, 's, 'l> serde::Serializer for &'r ConfigSerializer<'r, 's, 'l> {
|
|
|
|
|
|
fn serialize_some<T: ?Sized>(self, value: &T) -> Result<Self::Ok, Self::Error>
|
|
|
where
|
|
|
- T: serde::Serialize {
|
|
|
-
|
|
|
+ T: serde::Serialize,
|
|
|
+ {
|
|
|
todo!()
|
|
|
}
|
|
|
|
|
|
- fn serialize_unit(self) -> Result<Self::Ok, Self::Error> { unreachable!() }
|
|
|
+ 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_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,
|
|
@@ -263,7 +319,7 @@ impl<'r, 's, 'l> serde::Serializer for &'r ConfigSerializer<'r, 's, 'l> {
|
|
|
) -> Result<Self::SerializeStruct, Self::Error> {
|
|
|
log::trace!("name: {name}");
|
|
|
|
|
|
- let new_prefix =
|
|
|
+ let new_prefix =
|
|
|
// are we at the root?
|
|
|
if name == "Config" {
|
|
|
String::new()
|
|
@@ -277,7 +333,7 @@ impl<'r, 's, 'l> serde::Serializer for &'r ConfigSerializer<'r, 's, 'l> {
|
|
|
qi: self.qi,
|
|
|
prefix: new_prefix,
|
|
|
};
|
|
|
-
|
|
|
+
|
|
|
Ok(subser)
|
|
|
}
|
|
|
|
|
@@ -318,7 +374,8 @@ impl<'r, 's, 'l> serde::Serializer for &'r ConfigSerializer<'r, 's, 'l> {
|
|
|
value: &T,
|
|
|
) -> Result<Self::Ok, Self::Error>
|
|
|
where
|
|
|
- T: serde::Serialize {
|
|
|
+ T: serde::Serialize,
|
|
|
+ {
|
|
|
todo!()
|
|
|
}
|
|
|
|
|
@@ -340,8 +397,8 @@ impl<'r, 's, 'l> serde::Serializer for &'r ConfigSerializer<'r, 's, 'l> {
|
|
|
value: &T,
|
|
|
) -> Result<Self::Ok, Self::Error>
|
|
|
where
|
|
|
- T: serde::Serialize {
|
|
|
-
|
|
|
+ T: serde::Serialize,
|
|
|
+ {
|
|
|
todo!()
|
|
|
}
|
|
|
}
|
|
@@ -503,9 +560,13 @@ impl<'de> serde::Deserializer<'de> for AtomicForwarder<'de> {
|
|
|
|
|
|
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()))?)
|
|
|
+ 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>
|