v2.0.0-beta.2
Pre-releaseDescription
The MongoDB Rust driver team is pleased to announce the v2.0.0-beta.2
release of the bson
crate. This is the third beta release in preparation for the 2.0.0
stable release, and it contains a few minor improvements and bug fixes that were not included in the first or second betas. This release will be included in v2.0.0-beta.2
of the driver. As with the previous beta releases, we do not intend to make any further breaking changes before v2.0.0
, but we may do so in another beta if any issues arise before then.
Highlighted changes
The following sections detail some of the more important changes included in this release. For a full list of changes, see the Full Release Notes section.
Add pretty-printed Debug
implementation to BSON types (RUST-282)
BSON related types now support being pretty-printed via the {:#?}
format specifier.
e.g.
let doc = doc! {
"oid": ObjectId::new(),
"arr": Bson::Array(vec! [
Bson::Null,
Bson::Timestamp(Timestamp { time: 1, increment: 1 }),
]),
"doc": doc! { "a": 1, "b": "data"},
};
println!("{:#?}", doc);
Prints the following:
Document({
"oid": ObjectId(
"60d60c360026a43f00e47007",
),
"arr": Array([
Null,
Timestamp {
time: 1,
increment: 1,
},
]),
"doc": Document({
"a": Int32(
1,
),
"b": String(
"data",
),
}),
})
Implement From<Option<T>>
for Bson
where T: Into<Bson>
(RUST-806)
A blanket From<Option<T>>
implementation was added for T
that implement Into<Bson>
. If the value is Some(T)
, the T
is converted into Bson
using T
's Into
implementation, and if it's None
, it will be converted into Bson::Null
.
A nice benefit of this is that Option<T>
can now be used in the bson!
and doc!
macros directly:
let some: Option<i32> = Some(5);
let none: Option<i32> = None;
let doc = doc! {
"some": some,
"none": none,
};
println!("{}", doc);
Prints:
{ "some": 5, "none": null }
Full Release Notes
New Features
- RUST-806 Implement
From<Option<T>>
forBson
whereT: Into<Bson>
- RUST-841 Mark
ObjectId::bytes
asconst
- RUST-868 Add
serialize_object_id_as_hex_string
serde helper
Bugfixes
- RUST-755 Use zeroed rather than uninitialized memory for decimal128 deserialization (thanks @5225225 for reporting!)
Improvements
- RUST-282 Add pretty-printed
Debug
implementation to BSON types - RUST-672 Introduce new
BinarySubtype
case for user-defined values - RUST-838 Improve
bson::DateTime::now()
performance (thanks @pymongo!) - RUST-846 Unify
Display
andDebug
implementations forBson
- RUST-861 Support deserializing
ObjectId
from non self-describing formats (thanks for reporting @univerz!) - RUST-876 Quote keys in Document's Display implementation
Task
- RUST-505 Add unit test for
Document::extend