Function bson::to_bson_with_options

source ยท
pub fn to_bson_with_options<T>(
    value: &T,
    options: SerializerOptions,
) -> Result<Bson>
where T: Serialize + ?Sized,
Expand description

Encode a T into a Bson value, configuring the underlying serializer with the provided options.

#[derive(Debug, Serialize)]
struct MyData {
    a: String,
}

let data = MyData { a: "ok".to_string() };
let options = SerializerOptions::builder().human_readable(false).build();
let bson = bson::to_bson_with_options(&data, options)?;
assert_eq!(bson, bson!({ "a": "ok" }));