Function bson2::to_bson_with_options [−][src]
pub fn to_bson_with_options<T: ?Sized>(
value: &T,
options: SerializerOptions
) -> Result<Bson> where
T: Serialize,
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" }));