Encoding and decoding support for BSON in Rust

Overview

bson-rs

crates.io crates.io

Encoding and decoding support for BSON in Rust

Index

Useful links

Installation

This crate works with Cargo and can be found on crates.io with a Cargo.toml like:

[dependencies]
bson = "1.2.0"

Overview of BSON Format

BSON, short for Binary JSON, is a binary-encoded serialization of JSON-like documents. Like JSON, BSON supports the embedding of documents and arrays within other documents and arrays. BSON also contains extensions that allow representation of data types that are not part of the JSON spec. For example, BSON has a datetime type and a binary data type.

// JSON equivalent
{"hello": "world"}

// BSON encoding
\x16\x00\x00\x00                   // total document size
\x02                               // 0x02 = type String
hello\x00                          // field name
\x06\x00\x00\x00world\x00          // field value
\x00                               // 0x00 = type EOO ('end of object')

BSON is the primary data representation for MongoDB, and this crate is used in the mongodb driver crate in its API and implementation.

For more information about BSON itself, see bsonspec.org.

Usage

BSON values

Many different types can be represented as a BSON value, including 32-bit and 64-bit signed integers, 64 bit floating point numbers, strings, datetimes, embedded documents, and more. To see a full list of possible BSON values, see the BSON specification. The various possible BSON values are modeled in this crate by the Bson enum.

Creating Bson instances

Bson values can be instantiated directly or via the bson! macro:

let string = Bson::String("hello world".to_string());
let int = Bson::Int32(5);
let array = Bson::Array(vec![Bson::Int32(5), Bson::Boolean(false)]);

let string: Bson = "hello world".into();
let int: Bson = 5i32.into();

let string = bson!("hello world");
let int = bson!(5);
let array = bson!([5, false]);

bson! has supports both array and object literals, and it automatically converts any values specified to Bson, provided they are Into<Bson>.

Bson value unwrapping

Bson has a number of helper methods for accessing the underlying native Rust types. These helpers can be useful in circumstances in which the specific type of a BSON value is known ahead of time.

e.g.:

let value = Bson::Int32(5);
let int = value.as_i32(); // Some(5)
let bool = value.as_bool(); // None

let value = bson!([true]);
let array = value.as_array(); // Some(&Vec<Bson>)

BSON documents

BSON documents are ordered maps of UTF-8 encoded strings to BSON values. They are logically similar to JSON objects in that they can contain subdocuments, arrays, and values of several different types. This crate models BSON documents via the Document struct.

Creating Documents

Documents can be created directly either from a byte reader containing BSON data or via the doc! macro:

let mut bytes = hex::decode("0C0000001069000100000000").unwrap();
let doc = Document::decode(&mut bytes.as_slice()).unwrap(); // { "i": 1 }

let doc = doc! {
   "hello": "world",
   "int": 5,
   "subdoc": { "cat": true },
};

doc! works similarly to bson!, except that it always returns a Document rather than a Bson.

Document member access

Document has a number of methods on it to facilitate member access:

let doc = doc! {
   "string": "string",
   "bool": true,
   "i32": 5,
   "doc": { "x": true },
};

// attempt get values as untyped Bson
let none = doc.get("asdfadsf"); // None
let value = doc.get("string"); // Some(&Bson::String("string"))

// attempt to get values with explicit typing
let string = doc.get_str("string"); // Ok("string")
let subdoc = doc.get_document("doc"); // Some(Document({ "x": true }))
let error = doc.get_i64("i32"); // Err(...)

Modeling BSON with strongly typed data structures

While it is possible to work with documents and BSON values directly, it will often introduce a lot of boilerplate for verifying the necessary keys are present and their values are the correct types. serde provides a powerful way of mapping BSON data into Rust data structures largely automatically, removing the need for all that boilerplate.

e.g.:

#[derive(Serialize, Deserialize)]
struct Person {
    name: String,
    age: i32,
    phones: Vec<String>,
}

// Some BSON input data as a `Bson`.
let bson_data: Bson = bson!({
    "name": "John Doe",
    "age": 43,
    "phones": [
        "+44 1234567",
        "+44 2345678"
    ]
});

// Deserialize the Person struct from the BSON data, automatically
// verifying that the necessary keys are present and that they are of
// the correct types.
let mut person: Person = bson::from_bson(bson_data).unwrap();

// Do things just like with any other Rust data structure.
println!("Redacting {}'s record.", person.name);
person.name = "REDACTED".to_string();

// Get a serialized version of the input data as a `Bson`.
let redacted_bson = bson::to_bson(&person).unwrap();

Any types that implement Serialize and Deserialize can be used in this way. Doing so helps separate the "business logic" that operates over the data from the (de)serialization logic that translates the data to/from its serialized form. This can lead to more clear and concise code that is also less error prone.

Breaking Changes

In the BSON specification, unsigned integer types are unsupported; for example, u32. In the older version of this crate (< v0.8.0), if you uses serde to serialize unsigned integer types into BSON, it will store them with Bson::Double type. From v0.8.0, we removed this behavior and simply returned an error when you want to serialize unsigned integer types to BSON. #72

For backward compatibility, we've provided a mod bson::compat::u2f to explicitly serialize unsigned integer types into BSON's floating point value as follows:

#[test]
fn test_compat_u2f() {
    #[derive(Serialize, Deserialize, Eq, PartialEq, Debug)]
    struct Foo {
        #[serde(with = "bson::compat::u2f")]
        x: u32
    }

    let foo = Foo { x: 20 };
    let b = bson::to_bson(&foo).unwrap();
    assert_eq!(b, Bson::Document(doc! { "x": Bson::Double(20.0) }));

    let de_foo = bson::from_bson::<Foo>(b).unwrap();
    assert_eq!(de_foo, foo);
}

In this example, we added an attribute #[serde(with = "bson::compat::u2f")] on field x, which will tell serde to use the bson::compat::u2f::serialize and bson::compat::u2f::deserialize methods to process this field.

Contributing

We encourage and would happily accept contributions in the form of GitHub pull requests. Before opening one, be sure to run the tests locally; check out the testing section for information on how to do that. Once you open a pull request, your branch will be run against the same testing matrix that we use for our continuous integration system, so it is usually sufficient to only run the integration tests locally against a standalone. Remember to always run the linter tests before opening a pull request.

Running the tests

Integration and unit tests

To actually run the tests, you can use cargo like you would in any other crate:

cargo test --verbose # runs against localhost:27017

Linter Tests

Our linter tests use the nightly version of rustfmt to verify that the source is formatted properly and the stable version of clippy to statically detect any common mistakes. You can use rustup to install them both:

rustup component add clippy --toolchain stable
rustup component add rustfmt --toolchain nightly

To run the linter tests, run the check-clippy.sh and check-rustfmt.sh scripts in the .evergreen directory:

bash .evergreen/check-clippy.sh && bash .evergreen/check-rustfmt.sh

Continuous Integration

Commits to master are run automatically on evergreen.

Comments
  • use random byte array instead of process_id and machine_id

    use random byte array instead of process_id and machine_id

    Hello o/

    I made a PR last week to compat for WASM compilation, adding a WASM specific method to use random bytes arrays to substitute a call to libc and getting hostname. In the discussion there, @saghm pointed out MongoDB drivers are now transitioning to use 5 random bytes instead of process_id and machine_id (spec). This PR implements that.

    In addition to using random bytes, this PR also:

    • [x] removes getter method for process_id (spec outlines that random value must not be accessible)
    • [x] removes process_id and machine_id entirely
    • [x] adds a check to travis for a WASM build

    This would be probably a semver major in semver terms, but I am not sure how you'd want to handle that (or deprecation for that matter).

    Thank you for your time!

    opened by lrlna 19
  • Support RawBson objects.

    Support RawBson objects.

    I'm working on an implementation of a zero-copy RawBson type / family of types, that store the input data as an &[u8], and operate directly on the bytes. This seems like a potentially better direct-from-the-wire format for the mongo crate, as it's more performant, and can still support many of the methods that the current Bson / OrderedDocument types support. Is this something you'd be interested in incorporating into this crate?

    It's a WIP, but as it stands now, you can directly instantiate a raw document from a &[u8], and from that query into the document using doc.get("key")?.as_<type>()?, similar to the current implementation. Currently, keying into the document is a linear operation, but could be sped up by validating the json & storing offsets in an index during construction.

    It would not support .get_mut() operations, and if we wanted to add that in the future, they would need to return (parsed) Bson objects, since in the general case you can't manipulate the data without allocating new buffers.

    I do envision having conversion functions from the raw types to the parsed ones, though the other direction would complicate things, because the current implementation uses &[u8], and there would need to be an owner of the raw data (Cow<'_, str>?).

    Code overview:

    pub struct RawBsonDoc<'a> {
        data: &'a [u8],
    }
    
    impl<'a> RawBsonDoc<'a> {
        pub fn new(data: &'a [u8]) -> Option<RawBsonDoc<'a>>;
        pub fn get(&'a self, key: &str) -> Option<RawBson<'a>>;
        pub fn to_parsed_doc(&self) -> OrderedDocument;
    }
    
    pub struct RawBsonArray<'a> {
        data: &'a [u8],
    }
    
    impl<'a> RawBsonArray<'a> {
        pub fn new(data: &'a [u8]) -> Option<RawBsonArray<'a>>;
        pub fn get(&'a self, key: &str) -> Option<RawBson<'a>>;
        pub fn to_parsed_array(&self) -> ??;
    }
    
    pub struct RawBson<'a> {
        bsontype: BsonType,
        data: &'a [u8],
    }
    
    impl<'a> RawBson<'a> {
        // only constructed from RawBsonDoc::get(&str) or RawBsonArray::get(usize)
        pub fn as_str(&self) -> Option<&'a str>;
        pub fn as_doc(&self) -> Option<RawBsonDoc<'a>>;
        pub fn as_array(&self) -> Option<RawBsonArray<'a>>;
        pub fn to_parsed_bson(&self) -> Bson;
    }
    
    // Not publicly exposed
    enum BsonType {
        String,
        Document,
        Array,
        // ...
    }
    

    Still under design: How this interfaces with encode and decode functions, impl serde::Deserialize types, and mongo query functions.

    tracked-in-jira 
    opened by jcdyer 18
  • Bugs in decoder found by fuzzing

    Bugs in decoder found by fuzzing

    Found the following:

    • [x] "thread '' panicked at 'No such local time'" From: chrono-0.2.25/src/offset/mod.rs:151 via src/decoder/mod.rs:172
    • [x] "thread '' panicked at 'attempt to multiply with overflow'" - src/decoder/mod.rs:172
    • [x] "thread '' panicked at 'attempt to subtract with overflow'" src/decoder/mod.rs:45
    • [ ] "AddressSanitizer failed to allocate 0xffffffff93000000 bytes" (whatever that means in real life)

    Full logs: https://gist.github.com/killercup/5e8623e0d8b0fe9868b45eb223ef51d8 (See last few lines for inputs used, in bytes or base64)

    See https://github.com/rust-fuzz/targets/pull/51 for sources, I ran it with

    $ env ASAN_OPTIONS="detect_odr_violation=0 allocator_may_return_null=1" ./run-fuzzer.sh bson read_bson
    

    cc https://github.com/rust-fuzz/targets/issues/39

    opened by killercup 17
  • ObjectId (de)serialization problem

    ObjectId (de)serialization problem

    ObjectId fails to deserialize with serde_qs after #220

        use bson::oid::ObjectId;
        let oid1 = ObjectId::from_str("60c2c48f0096ee4d0025cc0c")?;
        let str = serde_qs::to_string(&oid1)?;
        dbg!((&oid1, &str));
        let oid2: ObjectId = serde_qs::from_str(&str)?;
        dbg!(&oid2);
    
    • before (bson = { git = "https://github.com/mongodb/bson-rust", rev = "99b50d0" })
    [allnet/src/main.rs:44] (&oid1, &str) = (
        ObjectId(60c2c48f0096ee4d0025cc0c),
        "%24oid=60c2c48f0096ee4d0025cc0c",
    )
    [allnet/src/main.rs:46] &oid2 = ObjectId(60c2c48f0096ee4d0025cc0c)
    
    • after (bson = { git = "https://github.com/mongodb/bson-rust", rev = "5f17b3d" })
    [allnet/src/main.rs:44] (&oid1, &str) = (
        ObjectId(60c2c48f0096ee4d0025cc0c),
        "%24oid=60c2c48f0096ee4d0025cc0c",
    )
    Error: failed with reason: cannot deserialize primitive at the top level.Try deserializing into a struct.
    

    (i'm using serde_qs inside thin wrapper to handle forms / query parameters in Rocket framework)

    tracked-in-jira 
    opened by univerz 15
  •  problem on DateTime<Utc> type

    problem on DateTime type

    Hi, https://github.com/mongodb-labs/mongo-rust-driver-prototype/issues/317#issue-465699554

    That's my issue. Mongodb-labs chose not to deal with my problem.

    opened by phantomxe 12
  • Decimal128 feature not storing the right value to MongoDB

    Decimal128 feature not storing the right value to MongoDB

    Hello,

    I'm having a fairly serious issue in using the decimal128 feature, with bson 2.0.0-beta.2.

    I created a really simple, compilable project that describes the issue: https://github.com/ale-rinaldi/rust-decimal-test

    The important part is here:

    /* uses */
    
    #[derive(Serialize)]
    struct TestData {
        pub(crate) my_date: bson::DateTime,
        pub(crate) my_decimal: bson::Decimal128,
        pub(crate) my_string: String,
    }
    
    #[tokio::main]
    async fn main() -> Result<(), Box<dyn Error>> {
        /* Code for connection */
    
        let data = TestData {
            my_date: bson::DateTime::from_millis(1278720000000),
            my_decimal: bson::Decimal128::from_u32(42),
            my_string: "foobar".to_string()
        };
        let doc = bson::to_document(&data).unwrap();
        collection.insert_one(doc, None).await.unwrap();
        Ok(())
    }
    

    So I'm creating a simple test struct with a Date, a Decimal128 and a String, and saving it to Mongo (I'm on MongoDB 4.4.7 but I tried this with various versions, even back to 4.1.13, and the issue is the same). What happens here is that, if I look at the created document using MongoDB Compass, the date and the string fields have the value that I except (2010-07-10T00:00:00.000+00:00 and foobar), while the decimal has no value 42 but 6.6E-1819.

    The strange thing is that, if I read the document back from Rust, the value of the returned Decimal128 is now correct (42).

    Am I totally missing the point here, or is it an actual problem with the bson serializer?

    Thanks

    opened by ale-rinaldi 11
  • How do I decode binary data?

    How do I decode binary data?

    Hi,

    I'm implementing an auth mechanism based on bson and sodiumoxide, and I'm having trouble decoding the challenge. Sodiumoxide treats plaintexts as a &[u8], so I'd like to use a binary string instead of a Unicode string for the challenge, but I can't seem to get bson to decode it correctly.

    Code

    With a "standard" string, everything works fine:

    #[derive(Serialize, Deserialize, Debug)]
    pub struct AuthChallenge {
        pub challenge: String,
    }
    
    // [...]
    
        let challenge: AuthChallenge = bson::from_bson(
            bson::Bson::Document(
                bson::decode_document(
                    &mut Cursor::new(&message.payload[..])
                ).chain_err(|| "Could not decode bson")?
            )
        ).expect("Decoding failed");
        info!("Challenge: {:?}", challenge.challenge);
    

    This yields:

    2018-03-08T08:22:04+01:00 - INFO - Received message ReqAuthentication (payload: [53, 0, 0, 0, 2, 99, 104, 97, 108, 108, 101, 110, 103, 101, 0, 33, 0, 0, 0, 49, 56, 55, 54, 50, 98, 57, 56, 98, 55, 99, 51, 52, 99, 50, 53, 98, 102, 57, 100, 99, 51, 49, 53, 52, 101, 52, 97, 53, 99, 97, 51, 0, 0])
    2018-03-08T08:22:04+01:00 - INFO - Challenge: "18762b98b7c34c25bf9dc3154e4a5ca3"
    

    However, if I changeString to Vec<u8> in the struct and change the server side to send a binary string (5) instead of a standard string (2), I get this:

    2018-03-08T08:28:12+01:00 - INFO - Received message ReqAuthentication (payload: [53, 0, 0, 0, 5, 99, 104, 97, 108, 108, 101, 110, 103, 101, 0, 32, 0, 0, 0, 0, 54, 55, 98, 54, 100, 53, 50, 99, 50, 101, 48, 51, 52, 52, 56, 49, 98, 52, 57, 101, 102, 51, 56, 56, 101, 100, 100, 54, 51, 98, 50, 102, 0])
    thread 'main' panicked at 'Decoding failed: InvalidType("a sequence")', /checkout/src/libcore/result.rs:906:4
    

    I'm also having trouble encoding the signature, because to_bson would always complain that there are no unsigned types in bson, so I ended up doing the encoding manually:

        bson::Bson::Binary(
            bson::spec::BinarySubtype::Generic,
            Vec::from(&signature[..])
        )
    

    Am I doing it wrong, or does bson not currently support binary strings correctly? Can I help in fixing it somehow?

    opened by Svedrin 11
  • OOM on huge allocation on malformed input (found through fuzzing)

    OOM on huge allocation on malformed input (found through fuzzing)

    Minimised base64 input: CgAAAAQAAAAAAA==

    Stack trace:

    ==3694748==ERROR: AddressSanitizer: requested allocation size 0xfffffffffffffffc (0x800 after adjustments for alignment, red zones etc.) exceeds maximum supported size of 0x10000000000 (thread T0)
        #0 0x55e5687daf12 in calloc /rustc/llvm/src/llvm-project/compiler-rt/lib/asan/asan_malloc_linux.cpp:154:3
        #1 0x55e56881c330 in bson::de::ensure_read_exactly::hf5185d965cc60fad (/home/jess/.cache/cargo/target/x86_64-unknown-linux-gnu/release/deserialize+0x21f330)
        #2 0x55e568819981 in bson::de::deserialize_array::ha4650ca0cb324222 (/home/jess/.cache/cargo/target/x86_64-unknown-linux-gnu/release/deserialize+0x21c981)
        #3 0x55e56881e3da in bson::de::deserialize_bson_kvp::hec5fdee461eb2b1b (/home/jess/.cache/cargo/target/x86_64-unknown-linux-gnu/release/deserialize+0x2213da)
        #4 0x55e568828b98 in bson::document::Document::decode::_$u7b$$u7b$closure$u7d$$u7d$::hf6f570c9035f9cf2 (/home/jess/.cache/cargo/target/x86_64-unknown-linux-gnu/release/deserialize+0x22bb98)
        #5 0x55e56881bcab in bson::de::ensure_read_exactly::h6a68518f15fd1165 (/home/jess/.cache/cargo/target/x86_64-unknown-linux-gnu/release/deserialize+0x21ecab)
        #6 0x55e568828653 in bson::document::Document::decode::hab1f24b5dff83160 (/home/jess/.cache/cargo/target/x86_64-unknown-linux-gnu/release/deserialize+0x22b653)
        #7 0x55e56884eb2c in rust_fuzzer_test_input (/home/jess/.cache/cargo/target/x86_64-unknown-linux-gnu/release/deserialize+0x251b2c)
        #8 0x55e568c35280 in __rust_try (/home/jess/.cache/cargo/target/x86_64-unknown-linux-gnu/release/deserialize+0x638280)
        #9 0x55e568c34edf in LLVMFuzzerTestOneInput (/home/jess/.cache/cargo/target/x86_64-unknown-linux-gnu/release/deserialize+0x637edf)
        #10 0x55e568c2c104 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) (/home/jess/.cache/cargo/target/x86_64-unknown-linux-gnu/release/deserialize+0x62f104)
        #11 0x55e568c2c882 in fuzzer::Fuzzer::MinimizeCrashLoop(std::vector<unsigned char, fuzzer::fuzzer_allocator<unsigned char> > const&) (/home/jess/.cache/cargo/target/x86_64-unknown-linux-gnu/release/deserialize+0x62f882)
        #12 0x55e568c1b0ef in fuzzer::MinimizeCrashInputInternalStep(fuzzer::Fuzzer*, fuzzer::InputCorpus*) (/home/jess/.cache/cargo/target/x86_64-unknown-linux-gnu/release/deserialize+0x61e0ef)
        #13 0x55e568c2500d in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) (/home/jess/.cache/cargo/target/x86_64-unknown-linux-gnu/release/deserialize+0x62800d)
        #14 0x55e56875f142 in main (/home/jess/.cache/cargo/target/x86_64-unknown-linux-gnu/release/deserialize+0x162142)
        #15 0x7f4586739b24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)
    
    tracked-in-jira 
    opened by 5225225 10
  • Exclude unneeded files from built package

    Exclude unneeded files from built package

    By default cargo publish all the content versionned by git. following insight given by cargo diet I used an explicit approach to exclude test dataset etc. from the final package.

    May clause #202

    opened by darnuria 9
  • How to merge two bson doc?

    How to merge two bson doc?

    let doc1 = doc! {
      "field1": "value1"
    }
    
    let doc2 = doc! {
      "field2": "value2"
    }
    

    Merged doc:

    let merged_doc = doc! {
      "field1": "value1",
      "field2": "value2",
    }
    

    I know there is an API: doc1.insert("field2", "value2"); I think it would be great if have an API like this: doc1.merge(doc2)

    tracked-in-jira 
    opened by gembin 9
  • Add raw bson types for zero-copy handling of bson wire data.

    Add raw bson types for zero-copy handling of bson wire data.

    Fixes #133

    • Implements a RawBsonDocBuf to hold a Vec<u8> of bson data, and a RawBson<'a> for a borrowed version of the same, along with various other types for supporting individual values and specific types within a bson type.
    • Implements lossless, but fallible conversion to the existing structured Bson type (fallible because well-formedness checking is not exhaustive at object creation time).
    • Implements serde deserialization to Bson and custom structs, including allowing custom structs to handle particular bson binary subtypes, and special handling for object ids utc datetimes, and other types that don't line up with serde's data model.
    • Provides impressive speed gains over deserializing directly to to the structured Bson type, and for deserializing to custom structs.
    • Where RawBson is slower (repeated random access to document members), speed of converting RawBson to Bson (without serde) is comparable to the existing direct decode from bytes to Bson (sometimes slightly faster, sometimes slightly slower).
    • Structured Bson is still needed for mutable access and constructing new bson documents.

    Caveats:

    • There may be some rough edges around handling serde deserialization of obscure types.
    • I haven't tried to handle Uuid and OldUuid types properly for different input formats. It just returns the raw bytes it got. This is apparently an unexpectedly tricky piece of Bson history, having to do with endianness, and which parts of a UUID count as a discrete value.
    • RawBson handles BinarySubtype::OldBinary differently than the existing Bson type, as the spec seems to indicate that the first four bytes should be treated as a second length specifier, but the Bson type doesn't do this.

    Looking forward to your feedback.

    tracked-in-jira 
    opened by jcdyer 9
  • Improve Docs

    Improve Docs

    The docs don't indicate how the serde serialization will be performed on ObjectID or Datetime. I suggest improving the documentation for objectID and Datetime to show how access the fields in a frontend that expects json.

    I also ask to improve the datetime documentation to include how to show the date in different formats.

    triage 
    opened by elibroftw 0
  • Stackoverflow via raw_deserialize fuzz target found by oss-fuzz

    Stackoverflow via raw_deserialize fuzz target found by oss-fuzz

    Versions/Environment

    1. What version of Rust are you using? rustc 1.64.0 (a55dd71d5 2022-09-19) binary: rustc commit-hash: a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52 commit-date: 2022-09-19 host: x86_64-unknown-linux-gnu release: 1.64.0 LLVM version: 14.0.6

    2. What operating system are you using? Ubuntu 20.04.5 LTS

    3. What versions of the driver and its dependencies are you using? (Run cargo pkgid mongodb & cargo pkgid bson) [email protected]

    Describe the bug

    stack overflows were reported by oss-fuzz in following reports.

    • https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52817
    • https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52650
    • https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52626
    • https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52577

    Raised by following target: https://github.com/mongodb/bson-rust/blob/89521946106e1d6c3af390175bb0485ef578664a/fuzz/fuzz_targets/raw_deserialize.rs#L7

    To Reproduce

    Report: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52817

    input: clusterfuzz-testcase-minimized-raw_deserialize-5117201896308736.txt

    use std::fs;
    use bson::Document;
    
    fn main() {
        // Issue 52817 
        let testcase = "clusterfuzz-testcase-minimized-raw_deserialize-5117201896308736.txt";
        let data = fs::read(testcase).unwrap();
        let _ = bson::from_slice::<Document>(&data);
    }
    

    Stacktrace from oss-fuzz:

    ==9391==ERROR: AddressSanitizer: stack-overflow on address 0x7ffd9a290f78 (pc 0x55908a3ac70b bp 0x7ffd9a2917b0 sp 0x7ffd9a290f80 T0)
    	      #0 0x55908a3ac70b in __asan_memset /rustc/llvm/src/llvm-project/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp:26:3
    	      #1 0x55908a706e17 in alloc::vec::Vec$LT$T$C$A$GT$::with_capacity_in::h91993c27457f12ee /rustc/42325c525b9d3885847a3f803abe53c562d289da/library/alloc/src/vec/mod.rs:673:9
    	      #2 0x55908a706e17 in alloc::vec::Vec$LT$T$GT$::with_capacity::h55aef06b654d3f85 /rustc/42325c525b9d3885847a3f803abe53c562d289da/library/alloc/src/vec/mod.rs:483:9
    	      #3 0x55908a706e17 in _$LT$serde..__private..de..content..ContentVisitor$u20$as$u20$serde..de..Visitor$GT$::visit_map::h2be5f6965d500378 /rust/registry/src/github.com-1ecc6299db9ec823/serde-1.0.147/src/private/de.rs:488:27
    	      #4 0x55908a48cc9f in bson::de::raw::Deserializer::deserialize_next::h6429396b2680e8c0 [bson-rust/src/de/raw.rs:265](https://github.com/mongodb/bson-rust/blob/89521946106e1d6c3af390175bb0485ef578664a/src/de/raw.rs#L265):25
    	      #5 0x55908a5097ce in _$LT$$RF$mut$u20$bson..de..raw..Deserializer$u20$as$u20$serde..de..Deserializer$GT$::deserialize_any::hc7f52e77742ce4d0 [bson-rust/src/de/raw.rs:394](https://github.com/mongodb/bson-rust/blob/89521946106e1d6c3af390175bb0485ef578664a/src/de/raw.rs#L394):9
    	      #6 0x55908a5097ce in serde::de::Deserializer::__deserialize_content::hedb31bd9bda44235 /rust/registry/src/github.com-1ecc6299db9ec823/serde-1.0.147/src/de/mod.rs:1235:9
    	      #7 0x55908a5097ce in _$LT$serde..__private..de..content..Content$u20$as$u20$serde..de..Deserialize$GT$::deserialize::ha8016b2aad96756f /rust/registry/src/github.com-1ecc6299db9ec823/serde-1.0.147/src/p
    [clusterfuzz-testcase-minimized-raw_deserialize-5117201896308736.txt](https://github.com/mongodb/bson-rust/files/9995817/clusterfuzz-testcase-minimized-raw_deserialize-5117201896308736.txt)
    rivate/de.rs:298:13
    	      #8 0x55908a5097ce in _$LT$core..marker..PhantomData$LT$T$GT$$u20$as$u20$serde..de..DeserializeSeed$GT$::deserialize::h75ed4dfc8c1da04e /rust/registry/src/github.com-1ecc6299db9ec823/serde-1.0.147/src/de/mod.rs:792:9
    	      #9 0x55908a5097ce in bson::de::raw::DocumentAccess::read_next_value::_$u7b$$u7b$closure$u7d$$u7d$::h3d046c2d6d55eecb [bson-rust/src/de/raw.rs:529](https://github.com/mongodb/bson-rust/blob/89521946106e1d6c3af390175bb0485ef578664a/src/de/raw.rs#L529):23
    	      #10 0x55908a5097ce in bson::de::raw::DocumentAccess::read::he264107c83f444be [bson-rust/src/de/raw.rs:514](https://github.com/mongodb/bson-rust/blob/89521946106e1d6c3af390175bb0485ef578664a/src/de/raw.rs#L514):19
    	      #11 0x55908a60159d in bson::de::raw::DocumentAccess::read_next_value::h39be94149dcc8755 [bson-rust/src/de/raw.rs:529](https://github.com/mongodb/bson-rust/blob/89521946106e1d6c3af390175bb0485ef578664a/src/de/raw.rs#L529):9
    	      #12 0x55908a60159d in _$LT$bson..de..raw..DocumentAccess$u20$as$u20$serde..de..MapAccess$
    [clusterfuzz-testcase-minimized-raw_deserialize-4857237554462720.txt](https://github.com/mongodb/bson-rust/files/10032173/clusterfuzz-testcase-minimized-raw_deserialize-4857237554462720.txt)
    GT$::next_value_seed::h844c6386ae10548a [bson-rust/src/de/raw.rs:556](https://github.com/mongodb/bson-rust/blob/89521946106e1d6c3af390175bb0485ef578664a/src/de/raw.rs#L556):9
    	      #13 0x55908a60159d in serde::de::MapAccess::next_entry_seed::h47f17a50131aca24 /rust/registry/src/github.com-1ecc6299db9ec823/serde-1.0.147/src/de/mod.rs:1837:34
    	      #14 0x55908a709240 in
    [clusterfuzz-testcase-minimized-raw_deserialize-4836406434594816.txt](https://github.com/mongodb/bson-rust/files/10032183/clusterfuzz-testcase-minimized-raw_deserialize-4836406434594816.txt)
    serde::de::MapAccess::next_entry::h5fd2be9f1d80e22e /rust/registry/src/github.com-1ecc6299db9ec823/serde-1.0.147/src/de/mod.rs:1885:9
    	      #15 0x55908a709240 in _$LT$serde..__private..de..content..ContentVisitor$u20$as$u20$serde..de..Visitor$GT$::visit_map::ha21372886463c904 /rust/registry/src/github.com-1ecc6299db9ec823/serde-1.0.147/src/private/de.rs:489:39
    

    Report: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52650

    input: clusterfuzz-testcase-minimized-raw_deserialize-4857237554462720.txt

    use std::fs;
    use bson::Document;
    
    fn main() {
        // Issue 52650;
        let testcase = "clusterfuzz-testcase-minimized-raw_deserialize-4857237554462720.txt";
        let data = fs::read(testcase).unwrap();
        let _ = bson::from_slice::<Document>(&data);
    }
    

    Stacktrace from oss-fuzz:

    ==744==ERROR: AddressSanitizer: stack-overflow on address 0x7ffc6a9fd400 (pc 0x55e2acb17624 bp 0x7ffc6a9ff310 sp 0x7ffc6a9fd400 T0)
    	    #0 0x55e2acb17624 in bson::de::raw::Deserializer::deserialize_next::h882e280f53fb0a4a [bson-rust/src/de/raw.rs:0](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L0)
    	    #1 0x55e2acb6c43e in _$LT$$RF$mut$u20$bson..de..raw..Deserializer$u20$as$u20$serde..de..Deserializer$GT$::deserialize_any::h7a4bd62580148f8b [bson-rust/src/de/raw.rs:394](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L394):9
    	    #2 0x55e2acb6c43e in serde::de::Deserializer::__deserialize_content::h9ecb32214c39783f /rust/registry/src/github.com-1ecc6299db9ec823/serde-1.0.147/src/de/mod.rs:1235:9
    	    #3 0x55e2acb6c43e in _$LT$serde..__private..de..content..Content$u20$as$u20$serde..de..Deserialize$GT$::deserialize::he42e0c66f86b4d1a /rust/registry/src/github.com-1ecc6299db9ec823/serde-1.0.147/src/private/de.rs:298:13
    	    #4 0x55e2acb6c43e in _$LT$core..marker..PhantomData$LT$T$GT$$u20$as$u20$serde..de..DeserializeSeed$GT$::deserialize::h5a644791fce37639 /rust/registry/src/github.com-1ecc6299db9ec823/serde-1.0.147/src/de/mod.rs:792:9
    	    #5 0x55e2acb6c43e in bson::de::raw::DocumentAccess::read_next_value::_$u7b$$u7b$closure$u7d$$u7d$::hf27a7f2cb2fa8813 [bson-rust/src/de/raw.rs:529](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L529):23
    	    #6 0x55e2acb6c43e in bson::de::raw::DocumentAccess::read::h3843ebaba5b3dc28 [bson-rust/src/de/raw.rs:514](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L514):19
    	    #7 0x55e2acc6db8d in bson::de::raw::DocumentAccess::read_next_value::ha711dac4185ef7b0 [bson-rust/src/de/raw.rs:529](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L529):9
    	    #8 0x55e2acc6db8d in _$LT$bson..de..raw..DocumentAccess$u20$as$u20$serde..de..MapAccess$GT$::next_value_seed::h37898bcf10c45a49 [bson-rust/src/de/raw.rs:556](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L556):9
    	    #9 0x55e2acc6db8d in serde::de::MapAccess::next_entry_seed::h80c95a819ea1ace8 /rust/registry/src/github.com-1ecc6299db9ec823/serde-1.0.147/src/de/mod.rs:1837:34
    	    #10 0x55e2acd76a40 in serde::de::MapAccess::next_entry::h2011998cb3add332 /rust/registry/src/github.com-1ecc6299db9ec823/serde-1.0.147/src/de/mod.rs:1885:9
    

    Report: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52626 input: clusterfuzz-testcase-minimized-raw_deserialize-4836406434594816.txt

    use std::fs;
    use bson::Document;
    
    fn main() {
        // Issue 52626;
        let testcase = "clusterfuzz-testcase-minimized-raw_deserialize-4836406434594816.txt"; 
        let data = fs::read(testcase).unwrap();
        let _ = bson::from_slice::<Document>(&data);
    }
    

    Stacktrace from oss-fuzz:

    ==11728==ERROR: AddressSanitizer: stack-overflow on address 0x7ffc9918df98 (pc 0x5614035c87eb bp 0x7ffc9918e7d0 sp 0x7ffc9918dfa0 T0)
    	SCARINESS: 10 (stack-overflow)
    	    #0 0x5614035c87eb in __asan_memset /rustc/llvm/src/llvm-project/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp:26:3
    	    #1 0x5614039269fc in alloc::vec::Vec$LT$T$C$A$GT$::with_capacity_in::h7954380e66d603c0 /rustc/a00f8ba7fcac1b27341679c51bf5a3271fa82df3/library/alloc/src/vec/mod.rs:673:9
    	    #2 0x5614039269fc in alloc::vec::Vec$LT$T$GT$::with_capacity::h0fc2b517892301b1 /rustc/a00f8ba7fcac1b27341679c51bf5a3271fa82df3/library/alloc/src/vec/mod.rs:483:9
    	    #3 0x5614039269fc in _$LT$serde..__private..de..content..ContentVisitor$u20$as$u20$serde..de..Visitor$GT$::visit_map::h8c91294fb3f4d9f6 /rust/registry/src/github.com-1ecc6299db9ec823/serde-1.0.147/src/private/de.rs:488:27
    	    #4 0x561403691bb7 in bson::de::raw::Deserializer::deserialize_document::_$u7b$$u7b$closure$u7d$$u7d$::hfeecf6c34d727547 [bson-rust/src/de/raw.rs:164](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L164):48
    	    #5 0x561403691bb7 in bson::de::raw::Deserializer::access_document::hf5ba42f424e5de49 [bson-rust/src/de/raw.rs:179](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L179):19
    	    #6 0x5614037090f2 in bson::de::raw::Deserializer::deserialize_document::h40074c69c1e27c9d [bson-rust/src/de/raw.rs:164](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L164):18
    	    #7 0x5614036c8931 in bson::de::raw::Deserializer::deserialize_next::h882e280f53fb0a4a [bson-rust/src/de/raw.rs:0](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L0)
    	    #8 0x56140371c43e in _$LT$$RF$mut$u20$bson..de..raw..Deserializer$u20$as$u20$serde..de..Deserializer$GT$::deserialize_any::h7a4bd62580148f8b [bson-rust/src/de/raw.rs:394](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L394):9
    	    #9 0x56140371c43e in serde::de::Deserializer::__deserialize_content::h9ecb32214c39783f /rust/registry/src/github.com-1ecc6299db9ec823/serde-1.0.147/src/de/mod.rs:1235:9
    	    #10 0x56140371c43e in _$LT$serde..__private..de..content..Content$u20$as$u20$serde..de..Deserialize$GT$::deserialize::he42e0c66f86b4d1a /rust/registry/src/github.com-1ecc6299db9ec823/serde-1.0.147/src/private/de.rs:298:13
    
    

    Report: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=52577 input: clusterfuzz-testcase-minimized-raw_deserialize-6190399018631168.txt

    use std::fs;
    use bson::Document;
    
    fn main() {
        // Issue 52577;
        let testcase = "clusterfuzz-testcase-minimized-raw_deserialize-6190399018631168.txt";
        let data = fs::read(testcase).unwrap();
        let _ = bson::from_slice::<Document>(&data);
    }
    

    Stacktrace from oss-fuzz:

    ==3055==ERROR: AddressSanitizer: stack-overflow on address 0x7ffe0ee9be80 (pc 0x560d4b0684be bp 0x7ffe0ee9c270 sp 0x7ffe0ee9be80 T0)
    	    #0 0x560d4b0684be in bson::de::raw::Deserializer::deserialize_document::h5b8f7843671e8310 [bson-rust/src/de/raw.rs:0](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L0)
    	    #1 0x560d4b02d5d1 in bson::de::raw::Deserializer::deserialize_next::h9adad8288f7a9a43 [bson-rust/src/de/raw.rs:0](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L0)
    	    #2 0x560d4b07b9ae in _$LT$$RF$mut$u20$bson..de..raw..Deserializer$u20$as$u20$serde..de..Deserializer$GT$::deserialize_any::h352f94485c5303cd [bson-rust/src/de/raw.rs:394](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L394):9
    	    #3 0x560d4b07b9ae in bson::de::serde::_$LT$impl$u20$serde..de..Deserialize$u20$for$u20$bson..bson..Bson$GT$::deserialize::hdbbe86a3a78f964e [bson-rust/src/de/serde.rs:125](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/serde.rs#L125):9
    	    #4 0x560d4b07b9ae in _$LT$core..marker..PhantomData$LT$T$GT$$u20$as$u20$serde..de..DeserializeSeed$GT$::deserialize::hdad341661e035275 /rust/registry/src/github.com-1ecc6299db9ec823/serde-1.0.147/src/de/mod.rs:792:9
    	    #5 0x560d4b07b9ae in bson::de::raw::DocumentAccess::read_next_value::_$u7b$$u7b$closure$u7d$$u7d$::h4e1f7e156f4e2faf [bson-rust/src/de/raw.rs:529](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L529):23
    	    #6 0x560d4b07b9ae in bson::de::raw::DocumentAccess::read::h668384ae23654d4d [bson-rust/src/de/raw.rs:514](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L514):19
    	    #7 0x560d4b1d4d73 in bson::de::raw::DocumentAccess::read_next_value::h7ea104877d7a2aec [bson-rust/src/de/raw.rs:529](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L529):9
    	    #8 0x560d4b1d4d73 in _$LT$bson..de..raw..DocumentAccess$u20$as$u20$serde..de..MapAccess$GT$::next_value_seed::h57d0146be3e7ab2b [bson-rust/src/de/raw.rs:556](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/raw.rs#L556):9
    	    #9 0x560d4b1d4d73 in serde::de::MapAccess::next_value::h7f9ea60461f6e885 /rust/registry/src/github.com-1ecc6299db9ec823/serde-1.0.147/src/de/mod.rs:1871:9
    	    #10 0x560d4b1d4d73 in _$LT$bson..de..serde..BsonVisitor$u20$as$u20$serde..de..Visitor$GT$::visit_map::hf4c99b1011a9ce33 [bson-rust/src/de/serde.rs:482](https://github.com/mongodb/bson-rust/blob/d499e645e24d4ebe92b50ab3b11ccd4db0db026a/src/de/serde.rs#L482):29
    
    opened by manunio 2
  • RUST-1508 Implement conversion traits between strings and ObjectId

    RUST-1508 Implement conversion traits between strings and ObjectId

    I'd like to be able to do things like

    fn query<K: TryInto<ObjectId>>(key: K) {}
    
    fn main() {
        let key = "000000000000000000000000";
        query(key);
    
        let key = String::from("000000000000000000000000");
        query(key);
    
        let key = ObjectId::new();
        query(key);
    }
    

    but it doesn't seem like the necessary conversion traits have been implemented. I'm not a Rust expert and so I cannot speak to what the solution is, but it would be really convenient to be able to both pass ObjectIds and types that can be turned into ObjectIds.

    tracked-in-jira 
    opened by clarkmcc 0
  • RUST-1110 bson::to_vec fail to serialize any `Serialize`

    RUST-1110 bson::to_vec fail to serialize any `Serialize`

    When trying to serialize Serialize object using bson::to_vec it gets to update_element_type which returns an error if the top level object is not ElementType::EmbeddedDocument

    if matches!(t, ElementType::EmbeddedDocument) {

    Is there a reason for this limitation? I tested the code without this check and it works.

    tracked-in-jira 
    opened by gkorland 2
  • Add `into_vec` serialization method for reusing allocated memory

    Add `into_vec` serialization method for reusing allocated memory

    During serialization, to_vec can get particularly hot by reallocating a large number of times. This PR adds a method to provide a pre-warmed Vec as input to avoid these reallocations. Since the Vec is given back, after the data is written, it can be reused.

    opened by djkoloski 0
Releases(v2.4.0)
  • v2.4.0(Aug 2, 2022)

    Description

    The MongoDB Rust driver team is pleased to announce the v2.4.0 release of the bson crate.

    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 below.

    Support for 1.x of the uuid crate

    The bson crate now has a uuid-1 feature that provides an API for interoperation with versions 1.x of the uuid crate, similar to the existing uuid-0_8 feature. Internal usage of uuid now uses 1.x, so downstream crates without a need for 0.8 will no longer transitively depend on both version.

    Builder for DateTime values

    The DateTime type now provides a builder that allows convenient construction from a given year, month, day, and optionally, an hour, minute, second and millisecond.

    Full Release Notes

    New Features

    • RUST-1305 Add support for version 1.x of the uuid crate to the bson crate
    • RUST-1198 Support creating bson::DateTime from a given year/month/date/hour/minute/second/millisecond

    Tasks

    • RUST-1398 Pin clippy version to 1.62.0
    • RUST-1374 Pin all dependencies when checking MSRV compilation
    Source code(tar.gz)
    Source code(zip)
  • v2.3.0(Jun 3, 2022)

    Description

    The MongoDB Rust driver team is pleased to announce the 2.3.0 release of the bson crate. This release increases the crate's MSRV to 1.53 and makes the crate's dependency on chrono optional.

    Full Release Notes

    Task

    • RUST-1263 Bump MSRV to 1.53 (#352)

    Improvement

    • RUST-1129 Replace chrono dependency with time (#352)
    Source code(tar.gz)
    Source code(zip)
  • v2.2.0(Apr 14, 2022)

    Description

    The MongoDB Rust driver team is pleased to announce the v2.2.0 release of the bson crate.

    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 below.

    Raw BSON (RUST-284, RUST-1045, RUST-1082, RUST-1109, RUST-1111, RUST-1119)

    Both of the existing ways of working with BSON values (the BSON type or using Serde) require parsing the values up-front. This can be a performance bottleneck in certain circumstances; to address this, we've introduced the RawBson, RawDocument, and RawArray types.

    These types provide an interface similar to the existing BSON types, but are backed by a buffer of BSON bytes rather than a fully parsed enum or hash map. This enables zero-copy reads with minimal parsing and highly memory-efficient manipulation.

    In tradeoff, these types do not provide the full set of operations that the standard ones can, and the performance of element access is O(N) rather than then average O(1) of the parsed types.

    Thanks to @jcdyer for contributing the initial implementation!

    Full Release Notes

    New Features

    • RUST-284 Incorporate raw BSON code from rawbson = "0.2.1" in mod raw (#229)
    • RUST-1045 Support appending to RawDocumentBuf (#326)
    • RUST-1109 Implement rawbson! and rawdoc! macros (#329)
    • RUST-1119 Add bson::to_raw_document_buf function (#330)
    • RUST-1111 Support deserializing RawBson from Bson (#331)
    • minor: raw BSON perf and API improvements (#335)

    Bugfixes

    • RUST-1243 Handle enum keys when deserializing a map from binary (#348) (thanks @George-Miao!)
    • RUST-1240 Fix potential underflow in length counting (#349)
    • RUST-1195 Add missing trait impls to Uuid (#345)
    Source code(tar.gz)
    Source code(zip)
  • v2.2.0-beta.1(Mar 31, 2022)

    Description

    The MongoDB Rust driver team is pleased to announce the v2.2.0-beta.1 release of the bson crate. This is the second beta release in preparation for the 2.2.0 stable release, and it contains some bug fixes that were not included in the first beta.

    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 below.

    Map types with enum keys (RUST-1243)

    This release fixes deserialization of map types using enum values as the keys; in the prior beta release this would fail with an "invalid type: string" error.

    Thanks to @George-Miao for reporting this bug!

    Length underflow in binary deserialization (RUST-1240)

    This release fixes a bug that caused parsing to erroneously continue when reading invalid length values. This bug would not have caused unsafe behavior (all binary buffer access is checked) but could have caused runtime panics or garbage parse results.

    Full Release Notes

    Bugfixes

    • RUST-1243 Handle enum keys when deserializing a map from binary (#348)
    • RUST-1240 Fix potential underflow in length counting (#349)
    Source code(tar.gz)
    Source code(zip)
  • v2.2.0-beta(Mar 25, 2022)

    Description

    The MongoDB Rust driver team is pleased to announce the v2.2.0-beta release of the bson crate.

    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 below.

    Raw BSON (RUST-284, RUST-1045, RUST-1082, RUST-1109, RUST-1111, RUST-1119)

    Both of the existing ways of working with BSON values (the BSON type or using Serde) require parsing the values up-front. This can be a performance bottleneck in certain circumstances; to address this, we've introduced the RawBson, RawDocument, and RawArray types.

    These types provide an interface similar to the existing BSON types, but are backed by a buffer of BSON bytes rather than a fully parsed enum or hash map. This enables zero-copy reads with minimal parsing and highly memory-efficient manipulation.

    In tradeoff, these types do not provide the full set of operations that the standard ones can, and the performance of element access is O(N) rather than then average O(1) of the parsed types.

    Thanks to @jcdyer for contributing the initial implementation!

    Full Release Notes

    New Features

    • RUST-284 Incorporate raw BSON code from rawbson = "0.2.1" in mod raw (#229)
    • RUST-1045 Support appending to RawDocumentBuf (#326)
    • RUST-1109 Implement rawbson! and rawdoc! macros (#329)
    • RUST-1119 Add bson::to_raw_document_buf function (#330)
    • RUST-1111 Support deserializing RawBson from Bson (#331)
    • minor: raw BSON perf and API improvements (#335)

    Bugfixes

    • RUST-1195 Add missing trait impls to Uuid (#345)
    Source code(tar.gz)
    Source code(zip)
  • v2.1.0(Dec 14, 2021)

    Description

    The MongoDB Rust driver team is pleased to announce the v2.1.0 release of the bson crate.

    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 below.

    Better Uuid ergonomics (RUST-819, RUST-465, RUST-1024)

    Working with UUIDs in BSON is a bit of a pain point, since the widely used Uuid type from the uuid crate doesn't serialize to or from BSON UUIDs (i.e. Binary with subtype 4) out of the box. To address this, we introduced a bson::Uuid type, which serializes as a BSON UUID when using bson::to_bson or bson::to_slice and uses uuid::Uuid's Serialize implementation for other formats.

    Additionally, we implemented the UUID driver specification, which enables easy conversion between Binary and bson::Uuid. It also adds support for handling BSON UUIDs that may have been serialized using the legacy format from one of the other MongoDB drivers (Python, Java, or C#).

    Lastly, we introduced support for using the serde_with crate to serialize uuid::Uuids to BSON. This requires the usage of the serde_with and uuid-0_8 feature flags. See the next section for more details.

    serde_with integration (RUST-1024)

    As mentioned in the previous section, we've added optional support for the serde_with crate via the serde_with feature flag. Right now, this allows for serialization of chrono::DateTime as bson::DateTime (with the chrono-0_4 feature flag) and uuid::Uuid as bson::Uuid (with the uuid-0_8 feature flag). The main improvement of serde_with annotations over the existing serde helpers is that they also work when the Uuid or DateTime type is nested, such as in an Option.

    #[serde_with::serde_as]
    #[derive(Serialize, Deserialize, Debug)]
    struct MyData {
        #[serde_as(as = "Option<bson::Uuid>")]
        uuid: Option<uuid::Uuid>,
    
        #[serde_as(as = "Option<bson::DateTime>")]
        dt: Option<chrono::DateTime<chrono::Utc>>,
    }
    
    let val = MyData {
        uuid: Some(uuid::Uuid::new_v4()),
        dt: chrono::Utc::now().into(),
    };
    
    // prints { "uuid": Binary(0x4, mMKbFkXEQMeLnfSNY+/NMg==), "dt": DateTime("2021-11-12 21:14:15.385 UTC") }
    println!("{}", bson::to_bson(&val)?);
    

    Support configuring Serializer and Deserializer to be not human-readable (RUST-1022)

    Serializer and Deserializer, which are used in bson::(to|from)_(bson|document), have never implemented the is_human_readable requirement from their respective serde traits, meaning they default to true. The raw serializer and deserializer, which are used in bson::to_vec and bson::from_slice, do report as non-human readable though. The unfortunate result of this inconsistency is that types that change their serialized format depending on whether the (de)serializer is human readable or not may produce different BSON depending on whether to_bson or to_vec are used. To help address this issue, this release includes support for configuring Serializer and Deserializer to report themselves as not human readable.

    #[derive(Debug, Deserialize, 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)?;
    
    let options = DeserializerOptions::builder().human_readable(false).build();
    let rt_data: MyData = bson::from_bson_with_options(bson, options)?;
    

    Full Release Notes

    New Features

    • RUST-465 Create a UUID wrapper type for serialization to / deserialization from BSON binary (#314)
    • RUST-977 Support parsing bson::DateTime from RFC 3339 formatting string even without chrono feature flag (#317)
    • RUST-1022 Introduce way to serialize to / deserialize from Bson with is_human_readable = false (#321)
    • RUST-1024 Add serde_with integration for composable serde helpers (#323)
    • RUST-787 Implement Display for all BSON types (#305)
    • RUST-966 Add BSON Binary subtype 7 (#315)

    Improvements

    • Remove time transitive dependency and clock feature flag from chrono (#316)
      • Thanks @roccodev!

    Bugfixes

    • RUST-1107 Fix array relaxed extended JSON (#325) (thanks @pacifistes!)
    Source code(tar.gz)
    Source code(zip)
  • v2.1.0-beta(Nov 16, 2021)

    Description

    The MongoDB Rust driver team is pleased to announce the v2.1.0-beta release of the bson crate. This release is a preview of the upcoming v2.1.0 release, which will be functionally the same but may contain fixes for any bugs identified in this beta.

    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 below.

    Better Uuid ergonomics (RUST-819, RUST-465, RUST-1024)

    Working with UUIDs in BSON is a bit of a pain point, since the widely used Uuid type from the uuid crate doesn't serialize to or from BSON UUIDs (i.e. Binary with subtype 4) out of the box. To address this, we introduced a bson::Uuid type, which serializes as a BSON UUID when using bson::to_bson or bson::to_slice and uses uuid::Uuid's Serialize implementation for other formats.

    Additionally, we implemented the UUID driver specification, which enables easy conversion between Binary and bson::Uuid. It also adds support for handling BSON UUIDs that may have been serialized using the legacy format from one of the other MongoDB drivers (Python, Java, or C#).

    Lastly, we introduced support for using the serde_with crate to serialize uuid::Uuids to BSON. This requires the usage of the serde_with and uuid-0_8 feature flags. See the next section for more details.

    serde_with integration (RUST-1024)

    As mentioned in the previous section, we've added optional support for the serde_with crate via the serde_with feature flag. Right now, this allows for serialization of chrono::DateTime as bson::DateTime (with the chrono-0_4 feature flag) and uuid::Uuid as bson::Uuid (with the uuid-0_8 feature flag). The main improvement of serde_with annotations over the existing serde helpers is that they also work when the Uuid or DateTime type is nested, such as in an Option.

    #[serde_with::serde_as]
    #[derive(Serialize, Deserialize, Debug)]
    struct MyData {
        #[serde_as(as = "Option<bson::Uuid>")]
        uuid: Option<uuid::Uuid>,
    
        #[serde_as(as = "Option<bson::DateTime>")]
        dt: Option<chrono::DateTime<chrono::Utc>>,
    }
    
    let val = MyData {
        uuid: Some(uuid::Uuid::new_v4()),
        dt: chrono::Utc::now().into(),
    };
    
    // prints { "uuid": Binary(0x4, mMKbFkXEQMeLnfSNY+/NMg==), "dt": DateTime("2021-11-12 21:14:15.385 UTC") }
    println!("{}", bson::to_bson(&val)?);
    

    Support configuring Serializer and Deserializer to be not human-readable (RUST-1022)

    Serializer and Deserializer, which are used in bson::(to|from)_(bson|document), have never implemented the is_human_readable requirement from their respective serde traits, meaning they default to true. The raw serializer and deserializer, which are used in bson::to_vec and bson::from_slice, do report as non-human readable though. The unfortunate result of this inconsistency is that types that change their serialized format depending on whether the (de)serializer is human readable or not may produce different BSON depending on whether to_bson or to_vec are used. To help address this issue, this release includes support for configuring Serializer and Deserializer to report themselves as not human readable.

    #[derive(Debug, Deserialize, 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)?;
    
    let options = DeserializerOptions::builder().human_readable(false).build();
    let rt_data: MyData = bson::from_bson_with_options(bson, options)?;
    

    Full Release Notes

    New Features

    • RUST-465 Create a UUID wrapper type for serialization to / deserialization from BSON binary (#314)
    • RUST-977 Support parsing bson::DateTime from RFC 3339 formatting string even without chrono feature flag (#317)
    • RUST-1022 Introduce way to serialize to / deserialize from Bson with is_human_readable = false (#321)
    • RUST-1024 Add serde_with integration for composable serde helpers (#323)
    • RUST-787 Implement Display for all BSON types (#305)
    • RUST-966 Add BSON Binary subtype 7 (#315)

    Improvements

    • Remove time transitive dependency and clock feature flag from chrono (#316)
      • Thanks @roccodev!

    Bugfixes

    • RUST-1107 Fix array relaxed extended JSON (#325) (thanks @pacifistes!)
    Source code(tar.gz)
    Source code(zip)
  • v2.0.0(Sep 7, 2021)

    Description

    The MongoDB Rust driver team is pleased to announce the v2.0.0 release of the bson crate. This release is the culmination of several months of work, and it contains a number of new features, API improvements, and bug fixes. This release will be included in v2.0.0 of the driver. It is intended that this release will be very stable and that bson will not have another major release for quite a long time.

    Note that the new minimum supported Rust version (MSRV) is now 1.48.0.

    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 below.

    Ensure API meets the Rust API Guidelines (RUST-765)

    There is a community maintained list of API guidelines that every stable Rust library is recommended to meet. The crate's existing API wasn't conforming to these guidelines exactly, so a number of improvements were made to ensure that it does. Here we highlight a few of the more important changes made in this effort.

    Stabilize or eliminate public dependencies on unstable crates (C-STABLE, RUST-739)

    bson included types from a number of unstable (pre-1.0) dependencies in its public API, which presented a problem for the stability of the library itself. In an effort to ensure that bson will no longer be subject to the semver breaks of unstable dependencies and can stay on 2.0 for the foreseeable future, the public dependencies on unstable types were removed altogether or gated behind feature flags.

    Here are the notable changes made as part of that:

    • Bson::DateTime(chrono::DateTime<Utc>) => Bson::DateTime(bson::DateTime), struct Datetime(pub chrono::DateTime) => struct DateTime { /* private fields */ }
      • Instead of directly including a DateTime from chrono (which is currently 0.4) in the Bson enum, the variant now wraps the bson::DateTime newtype defined within bson, and that newtype also no longer wraps a chrono::DateTime. This way the dependency on chrono can be updated to new semver breaking versions without having to update bson's major version.
      • To ease in the construction and usage of the newtype from chrono::DateTime, the chrono-0_4 feature flag can be enabled, which includes a From<chrono::DateTime> implementation for bson::DateTime and a From<bson::DateTime> implementation for chrono::DateTime, as well as some serde helpers.
    • Document::get_datetime returns a ValueAccessResult of &bson::DateTime instead of &chrono::DateTime
    • Bson::as_datetime returns an Option of &bson::DateTime instead of &chrono::DateTime
    • ObjectId::timestamp returns a crate::DateTime instead of chrono::DateTime
    • oid::Error no longer wraps hex::FromHexError (the hex crate is 0.4), see below for details.
    • The Uuid serde helpers, as well as From<Uuid> implementations for Bson and Binary, are now gated behind the uuid-0_8 feature flag.

    Accept impl AsRef<str> in Document methods (C-GENERIC, RUST-765)

    The methods on Document that accepted keys previously accepted them as &str. They were updated to accept impl AsRef<str> instead to allow other string-like types to be used for key lookup, such as String.

    Use more standard conversion constructors for ObjectId (C-CONV-TRAITS, C-CTOR, RUST-789)

    ObjectId previously had three constructors: new, with_bytes, and with_string. The latter two were a bit inconsistent with the functions they performed and with similar constructors for related types in the Rust ecosystem. To remedy this, the constructors were updated to match uuid::Uuid's constructor API:

    • ObjectId::with_bytes => const ObjectId::from_bytes
    • ObjectId::with_string => ObjectId::parse_str

    Error naming improvements (C-WORD-ORDER, C-STABLE)

    Some error variants were renamed or restructured to be clearer or more informative. A complete summary of the changes are as follows:

    • bson::de::Error:
      • IoError => Io
      • FromUtf8Error => InvalidUtf8String
      • SyntaxError => removed, consolidated into DeserializationError.
      • InvalidTimestamp(i64) => InvalidDateTime { key: String, datetime: i64 }
    • bson::ser::Error:
      • IoError => Io
      • InvalidMapKeyType { key: Bson } => InvalidDocumentKey(Bson)
      • UnsupportedUnsignedType => removed
      • UnsignedTypesValueExceededRange => UnsignedIntegerExceededRange(u64)
    • oid::Error:
      • ArgumentError => removed
      • FromHexError => removed, replaced by the new InvalidHexStringCharacter and InvalidHexStringLength variants

    Other miscellaneous changes

    There were some other smaller breaking changes made as part of this as well:

    • Ensure public structs are future proof by marking them as non_exhaustive (C-STRUCT-PRIVATE)
    • document::DocumentIterator and document::DocumentIntoIterator renamed to document::Iter and document::IntoIter (C-ITER-TY)

    Enable the u2i behavior by default (RUST-968)

    In the 1.x version of bson, unsigned integers could not be serialized to BSON by default, but the u2i feature flag could be enabled to allow them to be serialized by automatically converting them to signed integers. After some investigation, it was determined that this u2i behavior was more consistent with the behavior of BSON libraries in other languages with unsigned integers, so bson now exhibits it by default, and the u2i feature flag was removed.

    Implement Clone on all error types (RUST-738)

    Previously many of the error types did not implement Clone, partially because many of them wrapped std::io::Error. Not implementing Clone made these errors difficult to work with, since they needed to be wrapped in an Arc or Rc in order to be passed around without transferring ownership. To avoid that requirement, we implemented Clone on all of the error types in bson. For the errors that wrapped std::io::Error, this required wrapping the wrapped std::io::Errors in Arcs.

    Implement Copy for ObjectId (RUST-680)

    Since ObjectId is just a wrapper around a 12-byte array, it is cheap to copy and therefore ought to implement Copy. As part of this, helpers on Document and Bson were updated to return owned ObjectIds instead of references to them.

    Thanks to @jcdyer for contributing this change!

    Replace linked-hash-map with indexmap (RUST-283)

    The dependency on the now unmaintained linked-hash-map was replaced with the more up-to-date indexmap. While this isn't a breaking change on its own, the Entry API of Document was updated to match both that of std::collections::HashMap and indexmap in a breaking way.

    Replace compat::u2f with serde helpers (RUST-756)

    The compat::u2f module has long existed to provide a way to serialize unsigned integers as BSON doubles, but it is inconsistent with the API we provide for these kinds of conversions today, namely the serde_helpers functions and modules. In order to present a more consistent API, the compat::u2f module was removed and most of its conversion helpers were rewritten as serde_helpers.

    Remove the decimal128 feature flag (RUST-960, #287)

    It was determined that the BSON serialization format that was used when the experimental decimal128 feature flag was enabled did not match the format expected by the database or other MongoDB tools and drivers. Because of this, the feature flag has been removed, as there was no way to use it correctly. See #282 for more details.

    If you were relying on this feature flag or are just interested in a complete decimal128 implementation, please let us know on #53.

    Support for serialization to and deserialization from BSON bytes (RUST-870, RUST-871, #276, #279)

    This release adds support for direct serialization to and deserialization from BSON bytes via bson::to_vec and bson::from_slice / bson::from_reader, eliminating the need to go through Document when converting between Rust data types and BSON bytes. This can enable significant performance improvements in certain circumstances; most notably, this will greatly improve the performance of the MongoDB driver, which in 2.0.0 will begin leveraging this functionality.

    Properly produce and ingest RFC 3339 (ISO 8601) datetimes in serde helpers (RUST-825)

    The iso_string_as_bson_datetime and bson_datetime_as_iso_string serde helpers were not producing or only accepting valid ISO 8601 strings. This has been fixed, and the helpers have been renamed to rfc3339_string_as_bson_datetime and bson_datetime_as_rfc3339_string to more accurately reflect the standard they conform to.

    Introduce serde helpers for legacy UUID formats (RUST-687)

    The Python, Java, and C# drivers all used to serialize UUIDs with different legacy formats, none of which were supported by the existing UUID serde helper. To add support for serializing and deserializing these UUIDs, new serde helpers were introduced for each of the legacy formats. These helpers are also gated behind the "uuid-0_8" feature flag.

    Thanks to @kenkoooo for contributing this change!

    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-687 Introduce serde helpers for legacy UUID formats (thanks @kenkoooo!)
    • RUST-688 Support for borrowed deserialization (#276)
    • RUST-870 Support deserializing directly from raw BSON (#276)
    • RUST-871 Support serializing directly to BSON bytes (#279)
    • RUST-680 Implement Copy for ObjectId (breaking)
    • RUST-747 Add serde helper to deserialize hex string from ObjectId (thanks @moka491!)
    • RUST-738 Implement Clone on BSON error types (breaking)
    • RUST-806 Implement From<Option<T>> for Bson where T: Into<Bson>
    • RUST-841 Mark ObjectId::bytes as const
    • RUST-868 Add serialize_object_id_as_hex_string serde helper
    • RUST-282 Add pretty-printed Debug implementation to BSON types

    Improvements

    • RUST-283 Replace linked-hash-map with indexmap (breaking)
    • RUST-711 Use imports_granularity=Crate in rustfmt config
    • RUST-756 Replace compat::u2f with serde helpers (breaking)
    • RUST-739 Don't re-export types from unstable dependencies (breaking)
    • RUST-789 Standardize on ObjectId conversion constructors (breaking)
    • RUST-788 Accept impl AsRef<str> instead of &str in Document methods (breaking)
    • RUST-765 Ensure API follows Rust API Guidelines (breaking)
    • RUST-889 Avoid going through hex string when deserializing ObjectId from raw bytes (#287)
      • Thanks @univerz for the POC for this!
    • RUST-960 Remove decimal128 feature flag and functionality (breaking)
    • RUST-882 Remove lossy From<u64> impl for Bson (#280) (breaking)
    • RUST-811 bson::DateTime ergonomic improvements (breaking)
    • RUST-815 Truncate chrono::DateTime to millisecond precision when converting to bson::DateTime (breaking) (thanks @vkill!)
    • RUST-826 Take ownership of self in ObjectId::to_hex (breaking)
    • RUST-672 Introduce new BinarySubtype case for user-defined values
    • RUST-838 Improve bson::DateTime::now() performance (thanks @pymongo!)
    • RUST-846 Unify Display and Debug implementations for Bson
    • RUST-861 Support deserializing ObjectId from non self-describing formats (thanks for reporting @univerz!)
    • RUST-876 Quote keys in Document's Display implementation
    • RUST-996 Bump rand dependency to 0.8 (thanks @seanpianka!)

    Bugfixes

    • RUST-884 Support deserializing DateTimes between the year 10,000 and 99,999
    • RUST-942 Generate 5 random bytes instead of 3 for ObjectIds (#284)
    • RUST-713 Fix underflow on BSON array and binary deserialization (thanks @gperinazzo and @5225225!)
    • RUST-799 Fix errors and panics caused by datetimes with large distance to epoch
    • RUST-825 Update serde helpers to properly conform with RFC 3339 (ISO 8601) (breaking)
    Source code(tar.gz)
    Source code(zip)
  • v2.0.0-beta.3(Aug 6, 2021)

    Description

    The MongoDB Rust driver team is pleased to announce the v2.0.0-beta.3 release of the bson crate. This is the fourth beta release in preparation for the 2.0.0 stable release, and it contains a few improvements and bug fixes that were not included in the previous betas. This release will be included in v2.0.0-beta.3 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.

    Remove the decimal128 feature flag (RUST-960, #287)

    It was determined that the BSON serialization format that was used when the experimental decimal128 feature flag was enabled did not match the format expected by the database or other MongoDB tools and drivers. Because of this, the feature flag has been removed, as there was no way to use it correctly. See #282 for more details.

    If you were relying on this feature flag or are just interested in a complete decimal128 implementation, please let us know on #53.

    Support for serialization to and deserialization from BSON bytes (RUST-870, RUST-871, #276, #279)

    This release adds support for direct serialization to and deserialization from BSON bytes via bson::to_vec and bson::from_slice / bson::from_reader, eliminating the need to go through Document when converting between Rust data types and BSON bytes. This can enable significant performance improvements in certain circumstances; most notably, this will greatly improve the performance of the MongoDB driver, which in 2.0.0-beta.3 will begin leveraging this functionality.

    Full Release Notes

    Bugfixes

    • RUST-884 Support deserializing DateTimes between the year 10,000 and 99,999
    • RUST-942 Generate 5 random bytes instead of 3 for ObjectIds (#284)

    New Features

    • RUST-688 Support for borrowed deserialization (#276)
    • RUST-870 Support deserializing directly from raw BSON (#276)
    • RUST-871 Support serializing directly to BSON bytes (#279)

    Improvements

    • RUST-889 Avoid going through hex string when deserializing ObjectId from raw bytes (#287)
      • Thanks @univerz for the POC for this!
    • RUST-960 Remove decimal128 feature flag and functionality (breaking)
    • RUST-882 Remove lossy From<u64> impl for Bson (#280) (breaking)
    Source code(tar.gz)
    Source code(zip)
  • v1.2.3(Aug 6, 2021)

    Description

    The MongoDB Rust driver team is pleased to announce the 1.2.3 release of the bson crate. This release includes a number of important bug fixes.

    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.

    Deprecate the decimal128 feature flag (RUST-960, #286)

    It was determined that the BSON serialization format that is used when the experimental decimal128 feature flag is enabled does not match the format expected by the database or other MongoDB tools and drivers. Because of this, it is not recommended for use and has been deprecated, and the flag will be removed altogether in 2.0.0. See #282 for more details.

    If you are relying on this feature flag or are just interested in a complete decimal128 implementation, please let us know on #53.

    Full Release Notes

    Bug

    • RUST-755 Use zeroed rather than uninitialized memory for decimal128 deserialization (#263)
      • Thanks for reporting @5225225!
    • RUST-880 Fix crash when deserializing/serializing Document that contains decimal128 (#285)
    • RUST-882 Fix or improve lossy From unsigned integer impls for Bson (#281)
    • RUST-942 Properly generate 5 random bytes instead of 3 for ObjectIds (#286)

    Improvement

    • RUST-960 Deprecate decimal128 feature flag (#288)
    Source code(tar.gz)
    Source code(zip)
  • v2.0.0-beta.2(Jun 25, 2021)

    Description

    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>> for Bson where T: Into<Bson>
    • RUST-841 Mark ObjectId::bytes as const
    • 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 and Debug implementations for Bson
    • 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
    Source code(tar.gz)
    Source code(zip)
  • v2.0.0-beta.1(Jun 1, 2021)

    Description

    The MongoDB Rust driver team is pleased to announce the v2.0.0-beta.1 release of the bson crate. This is the second beta release in preparation for the 2.0.0 stable release, and it contains a few breaking changes, API improvements, and bug fixes that were not included in the first beta. This release will be included in v2.0.0-beta.1 of the driver. As with the previous release, 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 breaking changes included in this release. For a full list of changes, see the Full Release Notes section.

    bson::DateTime truncates to millisecond precision (RUST-815)

    In the previous beta, we included a change that made it an error to attempt to serialize a chrono::DateTime or bson::DateTime that had nonzero microseconds or nanoseconds, since BSON itself only supports millisecond precision. In practice, this ended up being difficult to deal with and broke users' existing code. To remedy this, serializing a chrono::DateTime via the chrono_datetime_as_bson_datetime serde helper automatically truncates the serialized date to millisecond precision rather than returning an error. Similarly, when converting to a bson::DateTime from a chrono::DateTime, the microseconds and nanoseconds are discarded.

    Thanks to @vkill for contributing this change!

    bson::DateTime ergonomic improvements (RUST-811)

    In the first beta, some changes were made to reduce the public dependency on the unstable chrono crate in the public API. This had the unintended effect of making converting between bson::DateTime and chrono::DateTime cumbersome and difficult to discover. To improve on that situation, the bson::DateTime::from_chrono and bson::DateTime::to_chrono methods were introduced to make conversion easier and more explicit.

    Given the now expanded presence of chrono, a pre 1.0 crate, in the public API from these changes, these new methods and the existing From implementations were moved to behind the "chrono-0_4" feature flag. This will enable us to continue to add support for new major versions of chrono without having to worry about polluting the public API surface or having to break it altogether. Once chrono reaches 1.0, such support will be included by default without the need for a feature flag. Note that the serde helpers that involve chrono had their version numbers dropped from their names as part of this.

    To enable the bson::DateTime type to be more useful on its own, the following methods were also introduced:

    • DateTime::now
    • DateTime::from_millis
    • DateTime::from_system_time
    • DateTime::to_system_time

    Better handling of datetimes that are very far from the Unix epoch (RUST-799)

    In BSON, any datetime within the range of a signed 64-bit integer of milliseconds from the Unix epoch is supported. This is not the case for chrono::DateTime, however, which led to deserialization errors or panics when dates outside of the chrono::DateTime's range were encountered. This has been fixed, and now bson::DateTime can represent any datetime that can be represented in BSON.

    Note that bson::DateTime::to_chrono will convert the date to chrono::MAX_DATETIME or chrono::MIN_DATETIME if attempting to convert directly would result in an error.

    Properly produce and ingest RFC 3339 (ISO 8601) datetimes in serde helpers (RUST-825)

    The iso_string_as_bson_datetime and bson_datetime_as_iso_string serde helpers were not producing or only accepting valid ISO 8601 strings. This has been fixed, and the helpers have been renamed to rfc3339_string_as_bson_datetime and bson_datetime_as_rfc3339_string to more accurately reflect the standard they conform to.

    uuid serde helpers were moved behind the "uuid-0_8" feature flag

    For consistency with the chrono changes, the uuid serde helpers were moved behind the "uuid-0_8" feature flag. This also will help prevent the public API from being filled with support for outdated versions of the uuid crate as new versions are released. Once uuid reaches 1.0, such support will be included by default without the need for a feature flag. Note that the serde helpers that involve uuid had the version numbers dropped from their names as part of this.

    Introduce serde helpers for legacy UUID formats (RUST-687)

    The Python, Java, and C# drivers all used to serialize UUIDs with different legacy formats, none of which were supported by the existing UUID serde helper. To add support for serializing and deserializing these UUIDs, new serde helpers were introduced for each of the legacy formats. These helpers are also gated behind the "uuid-0_8" feature flag.

    Thanks to @kenkoooo for contributing this change!

    Full Release Notes

    New Features

    • RUST-687 Introduce serde helpers for legacy UUID formats (thanks @kenkoooo!)

    Bugfixes

    • RUST-799 Fix errors and panics caused by datetimes with large distance to epoch
    • RUST-825 Update serde helpers to properly conform with RFC 3339 (ISO 8601) (breaking)

    Improvements

    • RUST-811 bson::DateTime ergonomic improvements (breaking)
    • RUST-815 Truncate chrono::DateTime to millisecond precision when converting to bson::DateTime (breaking) (thanks @vkill!)
    • RUST-826 Take ownership of self in ObjectId::to_hex (breaking)
    Source code(tar.gz)
    Source code(zip)
  • v2.0.0-beta(May 14, 2021)

    Description

    The MongoDB Rust driver team is pleased to announce the v2.0.0-beta release of the bson crate in preparation for the 2.0.0 stable release. This release contains a number of breaking changes, API improvements, new features, and bug fixes, and it will be included in v2.0.0-beta of the driver. It was not included in the previous driver alpha releases, however.

    Highlighted breaking changes

    The following sections detail some of the more important breaking changes included in this release. For a full list of changes, see the Full Release Notes section.

    Ensure API meets the Rust API Guidelines (RUST-765)

    There is a community maintained list of API guidelines that every stable Rust library is recommended to meet. The crate's existing API wasn't conforming to these guidelines exactly, so a number of improvements were made to ensure that it does. Here we highlight a few of the more important changes made in this effort.

    Stabilize or eliminate public dependencies on unstable crates (C-STABLE, RUST-739)

    bson included types from a number of unstable (pre-1.0) dependencies in its public API, which presented a problem for the stability of the library itself. In an effort to ensure that bson will no longer be subject to the semver breaks of unstable dependencies and can stay on 2.0 for the foreseeable future, the public dependencies on unstable types were removed altogether or stabilized such that they will always be present.

    Here are the notable changes made as part of that:

    • Bson::DateTime(chrono::DateTime<Utc>) => Bson::DateTime(bson::DateTime)
      • Instead of directly including a DateTime from chrono (which is currently 0.4), the variant now wraps the bson::DateTime newtype defined within bson. This way the dependency on chrono can be updated to new semver breaking versions without having to update its major version.
      • To ease in the construction and usage of this type, From<chrono_0_4::DateTime> is implemented for bson::DateTime, and From<bson::DateTime> is implemented for chrono_0_4::DateTime. As new semver breaking versions of chrono are released, these From implementations will continue to exist, and in new minor versions of bson, new From implementations for the new versions of chrono will be added while continuing to maintain the old ones. This is achieved by having bson depend on multiple semver-incompatible versions of chrono. This way, users of chrono 0.4 will not have their code broken when updating bson versions, but users of chrono 0.5+ will also be able to easily work with bson::DateTime.
    • struct Datetime(pub chrono::DateTime) => struct DateTime { /* private fields */ }
      • Same reasoning applies as for the above bullet
    • Document::get_datetime returns a ValueAccessResult of &bson::DateTime instead of &chrono::DateTime
    • Bson::as_datetime returns an Option of &bson::DateTime instead of &chrono::DateTime
    • ObjectId::timestamp returns a crate::DateTime instead of chrono::DateTime
    • oid::Error no longer wraps hex::FromHexError (the hex crate is 0.4), see below for details.
    • The serde_helpers that interface with unstable dependencies are versioned
      • e.g. chrono_datetime_as_bson_datetime => chrono_0_4_datetime_as_bson_datetime

    Accept impl AsRef<str> in Document methods (C-GENERIC, RUST-765)

    The methods on Document that accepted keys previously accepted them as &str. They were updated to accept impl AsRef<str> instead to allow other string-like types to be used for key lookup, such as String.

    Use more standard conversion constructors for ObjectId (C-CONV-TRAITS, C-CTOR, RUST-789)

    ObjectId previously had three constructors: new, with_bytes, and with_string. The latter two were a bit inconsistent with the functions they performed and with similar constructors for related types in the Rust ecosystem. To remedy this, the constructors were updated to match uuid::Uuid's constructor API:

    • ObjectId::with_bytes => const ObjectId::from_bytes
    • ObjectId::with_string => ObjectId::parse_str

    Error naming improvements (C-WORD-ORDER, C-STABLE)

    Some error variants were renamed or restructured to be clearer or more informative. A complete summary of the changes are as follows:

    • bson::de::Error:
      • IoError => Io
      • FromUtf8Error => InvalidUtf8String
      • SyntaxError => removed, consolidated into DeserializationError.
      • InvalidTimestamp(i64) => InvalidDateTime { key: String, datetime: i64 }
    • bson::ser::Error:
      • IoError => Io
      • InvalidMapKeyType { key: Bson } => InvalidDocumentKey(Bson)
      • UnsupportedUnsignedType => UnsupportedUnsignedInteger(u64)
      • UnsignedTypesValueExceededRange => UnsignedIntegerExceededRange(u64)
    • oid::Error:
      • ArgumentError => removed
      • FromHexError => removed, replaced by the new InvalidHexStringCharacter and InvalidHexStringLength variants

    Other miscellaneous changes

    There were some other smaller breaking changes made as part of this as well:

    • Ensure public structs are future proof by marking them as non_exhaustive (C-STRUCT-PRIVATE)
    • document::DocumentIterator and document::DocumentIntoIterator renamed to document::Iter and document::IntoIter (C-ITER-TY)
    • Deprecated Decimal128 conversion constructors removed (C-CONV)

    Implement Clone on all error types (RUST-738)

    Previously many of the error types did not implement Clone, partially because many of them wrapped std::io::Error. Not implementing Clone made these errors difficult to work with, since they needed to be wrapped in an Arc or Rc in order to be passed around without transferring ownership. To avoid that requirement, we implemented Clone on all of the error types in bson. For the errors that wrapped std::io::Error, this required wrapping the wrapped std::io::Errors in Arcs.

    Implement Copy for ObjectId (RUST-680)

    Since ObjectId is just a wrapper around a 12-byte array, it is cheap to copy and therefore ought to implement Copy. As part of this, helpers on Document and Bson were updated to return owned ObjectIds instead of references to them.

    Thanks to @jcdyer for contributing this change!

    Replace linked-hash-map with indexmap (RUST-283)

    The dependency on the now unmaintained linked-hash-map was replaced with the more up-to-date indexmap. While this isn't a breaking change on its own, the Entry API of Document was updated to match both that of std::collections::HashMap and indexmap in a breaking way.

    Replace compat::u2f with serde helpers (RUST-756)

    The compat::u2f module has long existed to provide a way to serialize unsigned integers as BSON doubles, but it is inconsistent with the API we provide for these kinds of conversions today, namely the serde_helpers functions and modules. In order to present a more consistent API, the compat::u2f module was removed and most of its conversion helpers were rewritten as serde_helpers.

    Full Release Notes

    New Features

    • RUST-680 Implement Copy for ObjectId (breaking)
    • RUST-747 Add serde helper to deserialize hex string from ObjectId (thanks @moka491!)
    • RUST-738 Implement Clone on BSON error types (breaking)

    Bugfixes

    • RUST-713 Fix underflow on BSON array and binary deserialization (thanks @gperinazzo and @5225225!)
    • RUST-798 Return error instead of silently loses precision when serializing sub-millisecond precision datetime to BSON

    Improvements

    • RUST-709 Update decimal dependency to 2.1.0
    • RUST-283 Replace linked-hash-map with indexmap (breaking)
    • RUST-711 Use imports_granularity=Crate in rustfmt config
    • RUST-756 Replace compat::u2f with serde helpers (breaking)
    • RUST-739 Don't re-export types from unstable dependencies (breaking)
    • RUST-789 Standardize on ObjectId conversion constructors (breaking)
    • RUST-788 Accept impl AsRef<str> instead of &str in Document methods (breaking)
    • RUST-765 Ensure API follows Rust API Guidelines (breaking)
    Source code(tar.gz)
    Source code(zip)
  • v1.2.2(Apr 7, 2021)

    Release Notes

    The MongoDB Rust Driver team is pleased to announce the v1.2.2 release of the BSON library.

    This release updates the base64 dependency to 0.13.0 (RUST-686). Thanks to @bugadani for contributing this fix!

    Source code(tar.gz)
    Source code(zip)
  • v1.2.1(Apr 6, 2021)

    Release Notes

    The MongoDB Rust Driver team is pleased to announce the v1.2.1 release of the BSON library.

    This release contains a fix for a crash that could occur in Document::from_reader when passed certain types of malformed input. Thank you to @5225225 for reporting the issue and @gperinazzo for fixing it! (RUST-713)

    Source code(tar.gz)
    Source code(zip)
  • v1.2.0(Feb 12, 2021)

    Description

    The MongoDB Rust Driver team is pleased to announce the v1.2.0 release of the BSON library.

    Release Notes

    Serde Integration Improvements

    This release contains several improvements to the library's integration with Serde.

    • RUST-506 introduces serde_helpers.rs which contains severals functions and modules to assist in customizing serialization and deserialization of user data types. These functions and modules are compatible with the Serde serialize_with and Serde with field attributes, respectively.
    • RUST-507 implements automatic deserialization of BSON number types into unsigned integer types.
    • RUST-602 implements automatic deserialization of the ObjectId type from a hexadecimal string.

    Other New Features

    • RUST-648 Reintroduce Document decoding with lossy UTF-8 encoding
    • RUST-589 Implement FromStr for ObjectId
    • RUST-364 Cache unique process value for oids
    • RUST-554 Support parsing $uuid as extended JSON representation for subtype 4 binary
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0(Aug 18, 2020)

    Description

    The MongoDB Rust Driver team is pleased to announce the v1.1.0 release of the BSON library.

    Release Notes

    In addition to the changes listed for the v1.1.0-beta, the following change was made since v1.0.0:

    New Features

    • RUST-503 Support serializing directly to and deserializing directly from Document
    Source code(tar.gz)
    Source code(zip)
  • v1.1.0-beta(Jul 30, 2020)

    Description

    The MongoDB Rust Driver team is pleased to announce the v1.1.0-beta release of the BSON library.

    Release Notes

    Bug fixes

    • RUST-511 Fix incorrect Deserialize requirement on generic type in from_bson
    • #197 Bump linked-hash-map due to fix unsoundness

    New Features

    • RUST-475 Add getter for timestamp from ObjectId

    Improvements

    Source code(tar.gz)
    Source code(zip)
  • v1.0.0(Jun 8, 2020)

    Description

    The MongoDB Rust Driver team is pleased to announce the first stable release of the BSON library, v1.0.0. Per semver requirements, no breaking changes will be made in future 1.x releases of this library.

    Major Changes

    See the release notes for v0.15.0 for details on the recent breaking changes in the BSON library.

    Source code(tar.gz)
    Source code(zip)
  • v0.15.0(Jun 3, 2020)

    Description

    The MongoDB Rust Driver team is pleased to announce the first beta of the BSON library, v0.15.0.

    Major Changes

    In preparation of stabilizing the API of the BSON library, we made a number of breaking changes. The individual changes are listed below in the release notes, each with a short description of why we made the change.

    Release Notes

    Breaking Changes

    • RUST-345 Improve naming of Bson and ElementType cases
      • Many of the names of our BSON types were inconsistent with the names used by other official MongoDB libraries. To better integrate with the existing ecosystem around MongoDB, we changed the names to match with the other librarires.
    • RUST-319 Convert variants of the BSON enum to use structs instead of multiple fields
      • Users have often asked to be able to serialize or deserialize directly to a certain BSON type rather than to a generic BSON value. Previously, the library was inconsistent in terms of which BSON types supported direct serialization/deserialization. We standardized this by defining a struct for each BSON type variant that previously had more than one field.
    • RUST-346 Update extended JSON format
      • The library previously implemented the old version of MongoDB's extended JSON format. We've updated the library to use extended JSON v2, which is the current extended JSON format used by all official MongoDB BSON libraries.
    • RUST-429 Move encode_document and decode_document into the Document namespace
      • Originally, the encode_document and decode_document were defined as free-floating functions for parity with serde_json. However, unlike serde_json::from_reader and serde_json::to_writer, our functions are not generic, so it makes more sense to derfine them as methods on the Document type.
    • RUST-447 Standardize API with other serde libraries
      • To better match terminology used in libraries like serde_json, we updated instances of the terms decode and encode to either use serialize and deserialize or to use terminology like reader or writer as appropriate.
    • RUST-410 Rename OrderedDocument to Document
      • Back when the Document type was originally changed to preserve the order of elements, Document was defined as an alias of the OrderedDocument type. Since the indirection can cause things like compiler error messages to be a little confusing, we've removed the alias and changed OrderedDocument to just be called Document.
    • RUST-313 Mark BSON enums as non-exhaustive where appropriate
      • In order to ensure that adding things like new error variants or new BSON subtypes don't cause breaking changes for users who pattern match them, we've marked many of the enums in the library as non_exhaustive.
    • RUST-427 Remove decode_document_utf8_lossy
      • decode_document_utf8_lossy was originally provided for parity with the standard library's String::from_utf8_lossy, but the BSON specification requires that all strings are encoded in UTF-8, so this method isn't particularly useful
    • RUST-315 Remove ObjectId::with_timestamp
      • Relying on the underlying format of an ObjectId is a bit of an antipattern, as the specification for how ObjectIds are generated can change (and has done so in the past), and this is not considered a breaking change for the BSON library. In particular, it's brittle to rely on the timestamp field due to the fact that it relies on the system time of the machine that generates the ObjectId; the time could be different across various machines due to time zone, differing NTP servers being synced to, or even just the machine being purposely configured to have an "incorrect" time. We standardize how ObjectIds are generated to ensure that they'll be unique across different machines and different drivers, but there are no user-facing guarantees about how they'll be generated. Users who need to perform queries over documents created in a certain time range should add a field with the time of insertion (and possibly update that on changes, if desired) and use that field when querying. See the documentation for $currentDate for some details on how this can be done.
    • RUST-316 Remove timestamp/counter getters on ObjectId
      • See the above explanation for Remove ObjectId::with_timestamp about the brittleness of relying on the underlying format of an ObjectId.
    • RUST-317 Remove oid::Error::HostnameError
      • Our ObjectId generation has been updated to no longer use the machine's hostname, so this error will never be returned by the library.
    • RUST-321 Remove Bson::as_*_mut helpers for types that are Copy
      • Types like i32 and bool that are Copy don't have a strong need for functionality that returns mutable references to them. Users who wish to modify the underlying value of a &mut Bson can still do so without introspecting the value by simply replacing what the reference points to.
    • RUST-318 Remove Document::insert_bson
      • Document::insert is already generic over values that implement Into<String> and Into<Bson>, which includes String and Bson themselves, so it can be used in any circumstance where Document::insert_bson was used.
    • RUST-320 Remove deprecated json methods from Bson
      • The existing JSON-related methods on the Bson type have been deprecated for over three years, so we've removed them in preparation of stabilizing the API.
    • RUST-343 Remove old doc! macro syntax
      • The original implementation of the doc! macro was written before Rust allowed macros to use the : character. Instead, the syntax => was used for key-value pairs. Rust lifted this restriction a few years ago, and the doc! macro was updated to allow the : to be used. In preparation of stabilizing the API, we've removed the old syntax, which isn't necessary anymore and likely has not been used for new code for a while.

    Bug fixes

    • RUST-443 BSON deserializer always ignores unknown fields
    • RUST-457 Fix Display implementation for Bson Binary type

    New Features

    • RUST-311 Support decoding Undefined / MinKey / MaxKey / DbPointer
    • RUST-390 Implement ordering for TimeStamp
    • RUST-445 Decimal128 round tripping

    Improvement

    • RUST-217 Rephrase unsupported/corrupt BSON messages
    • RUST-312 Remove implementation of Error::description in BSON library
    • RUST-314 Remove constants for subtypes and element types
    • RUST-430 Label BSON error enum cases
    • RUST-437 Add documentation for BSON library error variants
    • RUST-438 Add more detailed examples to BSON library documentation
    • RUST-444 Replace unneeded serde enum cases in DecoderError
    Source code(tar.gz)
    Source code(zip)
  • v0.14.1(Mar 17, 2020)

    Description

    The MongoDB Rust driver team is pleased to announce a new bugfix release of the BSON library, v0.14.1.

    Release Notes

    Bug fixes

    • RUST-305 Fix deserialization of non-generic binary

    New features

    • #130 More Bson From<> implementations

    Improvements

    • #131 Clean macro imports

    Contributors

    Thanks to @jcdyer for the pull requests!

    Source code(tar.gz)
    Source code(zip)
  • v0.14.0(Aug 31, 2019)

    Language features updates:

    • Rust Edition 2018
    • Uses dyn keyword for Trait objects.

    New features:

    • #118 Add Decimal128 supports with decimal crate, could be enabled by feature decimal128
      • Experimental feature, may be replaced by #125 in the future
    • #119 Implement Extend<(String, Bson)> for OrderedDocument
    • #114 Use random byte array instead of process_id and machine_id (for WASM supports)
    • #123 Add mutable accessors for Bson variants (as_*_mut())
    • #124 Uses std::convert::TryFrom instead of try_from crate

    Bug fixed:

    • #116 Malformed BSON may trigger large memory allocation. Binary type is limited to maximum length 16MiB.
    Source code(tar.gz)
    Source code(zip)
  • v0.13.0(Aug 11, 2018)

  • v0.12.3(Jul 30, 2018)

    • #102 #100 Optimizations. The most important improvement is to remove unnecessary to_owned()/clone()/to_string() allocations.
    • [BREAKING] (MAYBE) Implements From<UtcDateTime> for DateTime<Utc> instead of Into<DateTime<Utc> for UtcDateTime.
    Source code(tar.gz)
    Source code(zip)
  • v0.12.2(Jul 11, 2018)

    • #99 - Implement TimeStamp serde serialisation
    • #98 - Fixed incorrect endianness for TimeStamp
    • #95 - Add i2u feature to allow auto converting between signed and unsigned integers.
    Source code(tar.gz)
    Source code(zip)
  • v0.12.1(Jul 3, 2018)

  • v0.12.0(Jul 3, 2018)

    • #89 Implemented special serialization/deserialization rules for bytes array in serde.
    • #64 Won't crash if the length of UTF-8 string is invalid.
    • Updated dependencies.
    Source code(tar.gz)
    Source code(zip)
  • v0.11.1(Feb 23, 2018)

  • v0.11.0(Jan 5, 2018)

  • v0.10.0(Oct 2, 2017)

Owner
mongodb
mongodb
A TOML encoding/decoding library for Rust

toml-rs A TOML decoder and encoder for Rust. This library is currently compliant with the v0.5.0 version of TOML. This library will also likely contin

Alex Crichton 1k Dec 30, 2022
Character encoding support for Rust

Encoding 0.3.0-dev Character encoding support for Rust. (also known as rust-encoding) It is based on WHATWG Encoding Standard, and also provides an ad

Kang Seonghoon 264 Dec 14, 2022
TLV-C encoding support.

TLV-C: Tag - Length - Value - Checksum TLV-C is a variant on the traditional [TLV] format that adds a whole mess of checksums and whatnot. Why, you as

Oxide Computer Company 3 Nov 25, 2022
A series of compact encoding schemes for building small and fast parsers and serializers

A series of compact encoding schemes for building small and fast parsers and serializers

Manfred Kröhnert 2 Feb 5, 2022
Variable-length signed and unsigned integer encoding that is byte-orderable for Rust

ordered-varint Provides variable-length signed and unsigned integer encoding that is byte-orderable. This crate provides the Variable trait which enco

Khonsu Labs 7 Dec 6, 2022
Implementation of Bencode encoding written in rust

Rust Bencode Implementation of Bencode encoding written in rust. Project Status Not in active developement due to lack of time and other priorities. I

Arjan Topolovec 32 Aug 6, 2022
A Gecko-oriented implementation of the Encoding Standard in Rust

encoding_rs encoding_rs an implementation of the (non-JavaScript parts of) the Encoding Standard written in Rust and used in Gecko (starting with Fire

Henri Sivonen 284 Dec 13, 2022
A HTML entity encoding library for Rust

A HTML entity encoding library for Rust Example usage All example assume a extern crate htmlescape; and use htmlescape::{relevant functions here}; is

Viktor Dahl 41 Nov 1, 2022
Entropy Encoding notebook. Simple implementations of the "tANS" encoder/decoder.

EntropyEncoding Experiments This repository contains my Entropy Encoding notebook. Entropy encoding is an efficient lossless data compression scheme.

Nadav Rotem 4 Dec 21, 2022
Rust implementation of CRC(16, 32, 64) with support of various standards

crc Rust implementation of CRC(16, 32, 64). MSRV is 1.46. Usage Add crc to Cargo.toml [dependencies] crc = "2.0" Compute CRC use crc::{Crc, Algorithm,

Rui Hu 120 Dec 23, 2022
A CSV parser for Rust, with Serde support.

csv A fast and flexible CSV reader and writer for Rust, with support for Serde. Dual-licensed under MIT or the UNLICENSE. Documentation https://docs.r

Andrew Gallant 1.3k Jan 5, 2023
Rust library for reading/writing numbers in big-endian and little-endian.

byteorder This crate provides convenience methods for encoding and decoding numbers in either big-endian or little-endian order. Dual-licensed under M

Andrew Gallant 811 Jan 1, 2023
pem-rs pem PEM jcreekmore/pem-rs [pem] — A Rust based way to parse and encode PEM-encoded data

pem A Rust library for parsing and encoding PEM-encoded data. Documentation Module documentation with examples Usage Add this to your Cargo.toml: [dep

Jonathan Creekmore 30 Dec 27, 2022
Free Rust-only Xbox ADPCM encoder and decoder

XbadPCM Safe (and optionally no-std) Rust crate for encoding and decoding Xbox ADPCM blocks. Decoding example Here is example code for decoding stereo

Snowy 5 Nov 20, 2022
Crate to parse and emit EDN

edn-rs Near Stable no breaking changes expected. Crate to parse and emit EDN This lib does not make effort to conform the EDN received to EDN Spec. Th

Julia Naomi 61 Dec 19, 2022
Fast and compact sets of bytes or ASCII characters

bset Fast and compact sets of bytes and ASCII characters, useful for searching, parsing and determining membership of a given byte in the given set. T

null 26 Jul 19, 2022
Decode SCALE bytes into custom types using a scale-info type registry and a custom Visitor impl.

scale-decode This crate attempts to simplify the process of decoding SCALE encoded bytes into a custom data structure given a type registry (from scal

Parity Technologies 6 Sep 20, 2022
rust-jsonnet - The Google Jsonnet( operation data template language) for rust

rust-jsonnet ==== Crate rust-jsonnet - The Google Jsonnet( operation data template language) for rust Google jsonnet documet: (http://google.github.io

Qihoo 360 24 Dec 1, 2022
MessagePack implementation for Rust / msgpack.org[Rust]

RMP - Rust MessagePack RMP is a pure Rust MessagePack implementation. This repository consists of three separate crates: the RMP core and two implemen

Evgeny Safronov 840 Dec 30, 2022