pub fn to_vec(value: &impl Serialize) -> Result<Vec<u8>, Error>
Expand description

Serializes value into a Vec<u8>.

See serializer for information about the data format.

Examples

Basic usage:

#[derive(Serialize)]
struct Labels {
    method: Method,
    path: String,
}

#[derive(Serialize)]
enum Method {
    #[serde(rename = "GET")]
    Get,
}

let labels = Labels {
    method: Method::Get,
    path: "/metrics".to_string(),
};

let serialized = to_vec(&labels).unwrap();

assert_eq!(serialized, br#"method="GET",path="/metrics""#);