Function serialize_with
pub fn serialize_with<T, S, F>(
value: &T,
serializer: S,
transform: F,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::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
use serde::{Serialize, Serializer};
fn my_serialize<T, S>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
T: Serialize,
S: Serializer,
{
noyalib::with::singleton_map_with::serialize_with(
value,
serializer,
|s| s.to_lowercase(),
)
}