Skip to main content

to_string_with_options

Function to_string_with_options 

Source
pub fn to_string_with_options<T: Serialize>(
    value: &T,
    options: SerializerOptions,
) -> Result<String, Error>
Expand description

Serialize a value to a YAML String, with SerializerOptions.

This is like to_string, but lets you control formatting and serialization behavior through the provided options.

Example

use serde::Serialize;
use serde_saphyr::SerializerOptions;

#[derive(Serialize)]
struct Foo { a: i32, b: bool }

let options = SerializerOptions::default();
let s = serde_saphyr::to_string_with_options(&Foo { a: 1, b: true }, options).unwrap();
assert!(s.contains("a: 1"));