Skip to content

Commit

Permalink
add compat mod for backward compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed May 28, 2017
1 parent 21a5a77 commit 383c472
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/bson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl Debug for Bson {
&Bson::FloatingPoint(p) => write!(f, "FloatingPoint({:?})", p),
&Bson::String(ref s) => write!(f, "String({:?})", s),
&Bson::Array(ref vec) => write!(f, "Array({:?})", vec),
&Bson::Document(ref doc) => write!(f, "Document({})", doc),
&Bson::Document(ref doc) => write!(f, "Document({:?})", doc),
&Bson::Boolean(b) => write!(f, "Boolean({:?})", b),
&Bson::Null => write!(f, "Null"),
&Bson::RegExp(ref pat, ref opt) => write!(f, "RegExp(/{:?}/{:?})", pat, opt),
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ mod bson;
mod encoder;
mod decoder;
pub mod ordered;
pub mod compat;
17 changes: 17 additions & 0 deletions tests/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,20 @@ fn test_ser_datetime() {
let xfoo: Foo = bson::from_bson(x).unwrap();
assert_eq!(xfoo, foo);
}


#[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);
}

0 comments on commit 383c472

Please sign in to comment.