pub fn serialize<T, S>(value: &T, serializer: S) -> Result<S::Ok, S::Error>where
T: Serialize,
S: Serializer,Expand description
Serialize a value as a singleton map.
For enums, this serializes the variant as a map where the key is the variant name and the value is the variant’s data.
§Examples
use noyalib::with::singleton_map;
#[derive(Debug, serde::Serialize, serde::Deserialize)]
enum Action {
Start,
Stop { graceful: bool },
}
#[derive(Debug, serde::Serialize, serde::Deserialize)]
struct Command {
#[serde(with = "singleton_map")]
action: Action,
}