pub fn serialize_with<T, S, F>(
value: &T,
serializer: S,
transform: F,
) -> Result<S::Ok, S::Error>Expand description
Serialize a value as a singleton map with custom key transformation.
This function is similar to
singleton_map::serialize but allows you
to transform the key (variant name) before serialization.
§Arguments
value- The value to serializeserializer- The serializer to usetransform- A function that transforms the variant name
§Examples
fn my_serialize<T, S>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
T: serde_core::Serialize,
S: serde_core::Serializer,
{
noyalib::with::singleton_map_with::serialize_with(
value,
serializer,
|s| s.to_lowercase(),
)
}