Function serialize
pub fn serialize<T, S>(
value: &T,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::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;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
enum Action {
Start,
Stop { graceful: bool },
}
#[derive(Debug, Serialize, Deserialize)]
struct Command {
#[serde(with = "singleton_map")]
action: Action,
}