You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
822 B
35 lines
822 B
use serde::{
|
|
de::{
|
|
self,
|
|
Unexpected,
|
|
},
|
|
Serializer,
|
|
Deserializer,
|
|
Deserialize,
|
|
};
|
|
|
|
/// Seiralize bool into "yes"/"no", just like the LunaNode API does.
|
|
pub fn serialize<S>(succ: &bool, serializer: S) -> Result<S::Ok, S::Error>
|
|
where
|
|
S: Serializer {
|
|
match succ {
|
|
true => serializer.serialize_str("yes"),
|
|
false => serializer.serialize_str("no"),
|
|
}
|
|
}
|
|
|
|
/// Deserialize bool from String with custom value mapping "yes" => true, "no" => false
|
|
pub fn deserialize<'de, D>(deserializer: D) -> Result<bool, D::Error>
|
|
where
|
|
D: Deserializer<'de>,
|
|
{
|
|
match String::deserialize(deserializer)?.as_ref() {
|
|
"yes" => Ok(true),
|
|
"no" => Ok(false),
|
|
other => Err(de::Error::invalid_value(
|
|
Unexpected::Str(other),
|
|
&"\"yes\" or \"no\"",
|
|
)),
|
|
}
|
|
}
|