Skip to content

Commit

Permalink
Added breaking changes in README
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed May 30, 2017
1 parent f25589c commit 8d396e8
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ This crate works with Cargo and can be found on

```toml
[dependencies]
bson = "0.7"
bson = "0.8"
```

## Usage
Link the library in _main.rs_:

Expand Down Expand Up @@ -68,3 +69,29 @@ let person_document = mongoCollection.find_one(Some(doc! { "_id" => "12345" }),
// Deserialize the document into a Person instance
let person = bson::from_bson(bson::Bson::Document(person_document))?
```

## 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::FloatingPoint` 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](https://github.com/zonyitoo/bson-rs/pull/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:

```rust
#[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::FloatingPoint(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.

0 comments on commit 8d396e8

Please sign in to comment.