to_string_with_options

Function to_string_with_options 

Source
pub fn to_string_with_options<'facet, T>(
    value: &T,
    options: &SerializeOptions,
) -> Result<String, SerializeError<JsonSerializeError>>
where T: Facet<'facet> + ?Sized,
Expand description

Serialize a value to a JSON string with custom options.

ยงExample

use facet::Facet;
use facet_json::{to_string_with_options, SerializeOptions};

#[derive(Facet)]
struct Person { name: String, age: u32 }

let person = Person { name: "Alice".into(), age: 30 };

// Compact output
let json = to_string_with_options(&person, &SerializeOptions::default()).unwrap();
assert_eq!(json, r#"{"name":"Alice","age":30}"#);

// Pretty output with tabs
let json = to_string_with_options(&person, &SerializeOptions::default().indent("\t")).unwrap();
assert!(json.contains('\n'));