serde_yml::value

Function to_value

Source
pub fn to_value<T>(value: T) -> Result<Value, Error>
where T: Serialize,
Expand description

Converts a serializable value into a serde_yml::Value.

This function is a convenience wrapper around the serde_yml::value::Serializer. It allows serializing a value of type T into a serde_yml::Value using the default serializer configuration.

ยงExamples

use serde::Serialize;
use serde_yml::to_value;

#[derive(Serialize)]
struct User {
    name: String,
    age: u32,
}

let user = User {
    name: "John Doe".to_string(),
    age: 30,
};

let yaml_value = to_value(user).unwrap();