Function bson::ser::to_bson

source · []
pub fn to_bson<T: ?Sized>(value: &T) -> Result<Bson> where
    T: Serialize
Expand description

Encode a T Serializable into a BSON Value.

The Serializer used by this function presents itself as human readable, whereas the one used in to_vec does not. This means that this function will produce different BSON than to_vec for types that change their serialization output depending on whether the format is human readable or not. To serialize to a Document with a serializer that presents itself as not human readable, use to_bson_with_options with SerializerOptions::human_readable set to false.