Skip to content

Commit dbc863c

Browse files
authored
RUST-345 Improve naming of Bson and ElementType cases (#164)
1 parent ed1740a commit dbc863c

File tree

19 files changed

+266
-262
lines changed

19 files changed

+266
-262
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ possible BSON values are modeled in this crate by the [`Bson`](https://docs.rs/b
7171

7272
```rust
7373
let string = Bson::String("hello world".to_string());
74-
let int = Bson::I32(5);
75-
let array = Bson::Array(vec![Bson::I32(5), Bson::Boolean(false)]);
74+
let int = Bson::Int32(5);
75+
let array = Bson::Array(vec![Bson::Int32(5), Bson::Boolean(false)]);
7676

7777
let string: Bson = "hello world".into();
7878
let int: Bson = 5i32.into();
@@ -90,7 +90,7 @@ is known ahead of time.
9090

9191
e.g.:
9292
```rust
93-
let value = Bson::I32(5);
93+
let value = Bson::Int32(5);
9494
let int = value.as_i32(); // Some(5)
9595
let bool = value.as_bool(); // None
9696

@@ -191,7 +191,7 @@ that is also less error prone.
191191

192192
## Breaking Changes
193193

194-
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)
194+
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](https://github.com/zonyitoo/bson-rs/pull/72)
195195

196196
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:
197197

@@ -206,7 +206,7 @@ fn test_compat_u2f() {
206206

207207
let foo = Foo { x: 20 };
208208
let b = bson::to_bson(&foo).unwrap();
209-
assert_eq!(b, Bson::Document(doc! { "x": Bson::FloatingPoint(20.0) }));
209+
assert_eq!(b, Bson::Document(doc! { "x": Bson::Double(20.0) }));
210210

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

examples/encode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fn main() {
88

99
let mut arr = Array::new();
1010
arr.push(Bson::String("blah".to_string()));
11-
arr.push(Bson::UtcDatetime(chrono::Utc::now()));
11+
arr.push(Bson::DateTime(chrono::Utc::now()));
1212
arr.push(Bson::ObjectId(oid::ObjectId::with_bytes([
1313
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1414
])));

serde-tests/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ fn application_decode_error() {
146146
}
147147
}
148148
}
149-
let d_good = Decoder::new(Bson::I64(5));
149+
let d_good = Decoder::new(Bson::Int64(5));
150150
let d_bad1 = Decoder::new(Bson::String("not an isize".to_string()));
151-
let d_bad2 = Decoder::new(Bson::I64(11));
151+
let d_bad2 = Decoder::new(Bson::Int64(11));
152152

153153
assert_eq!(Range10(5), t!(Deserialize::deserialize(d_good)));
154154

0 commit comments

Comments
 (0)