diff --git a/src/bson.rs b/src/bson.rs index 2778d7f0..63534be6 100644 --- a/src/bson.rs +++ b/src/bson.rs @@ -449,7 +449,7 @@ impl Bson { Bson::UtcDatetime(ref v) => { doc! { "$date": { - "$numberLong" => (v.timestamp() * 1000) + v.nanosecond() as i64 / 1_000_000, + "$numberLong": (v.timestamp() * 1000) + v.nanosecond() as i64 / 1_000_000, } } } @@ -461,7 +461,7 @@ impl Bson { #[cfg(feature = "decimal128")] Bson::Decimal128(ref v) => { doc! { - "$numberDecimal" => (v.to_string()) + "$numberDecimal": (v.to_string()) } } Bson::Undefined => { diff --git a/src/macros.rs b/src/macros.rs index 8cfcaca1..bef0e7bc 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -92,56 +92,31 @@ macro_rules! bson { }; // Next value is `null`. - (@object $object:ident ($($key:tt)+) (=> null $($rest:tt)*) $copy:tt) => { - $crate::bson!(@object $object [$($key)+] ($crate::bson!(null)) $($rest)*); - }; - (@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => { $crate::bson!(@object $object [$($key)+] ($crate::bson!(null)) $($rest)*); }; // Next value is an array. - (@object $object:ident ($($key:tt)+) (=> [$($array:tt)*] $($rest:tt)*) $copy:tt) => { - $crate::bson!(@object $object [$($key)+] ($crate::bson!([$($array)*])) $($rest)*); - }; - (@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => { $crate::bson!(@object $object [$($key)+] ($crate::bson!([$($array)*])) $($rest)*); }; // Next value is a map. - (@object $object:ident ($($key:tt)+) (=> {$($map:tt)*} $($rest:tt)*) $copy:tt) => { - $crate::bson!(@object $object [$($key)+] ($crate::bson!({$($map)*})) $($rest)*); - }; - (@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => { $crate::bson!(@object $object [$($key)+] ($crate::bson!({$($map)*})) $($rest)*); }; // Next value is an expression followed by comma. - (@object $object:ident ($($key:tt)+) (=> $value:expr , $($rest:tt)*) $copy:tt) => { - $crate::bson!(@object $object [$($key)+] ($crate::bson!($value)) , $($rest)*); - }; - (@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => { $crate::bson!(@object $object [$($key)+] ($crate::bson!($value)) , $($rest)*); }; // Last value is an expression with no trailing comma. - (@object $object:ident ($($key:tt)+) (=> $value:expr) $copy:tt) => { - $crate::bson!(@object $object [$($key)+] ($crate::bson!($value))); - }; - (@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => { $crate::bson!(@object $object [$($key)+] ($crate::bson!($value))); }; // Missing value for last entry. Trigger a reasonable error message. - (@object $object:ident ($($key:tt)+) (=>) $copy:tt) => { - // "unexpected end of macro invocation" - $crate::bson!(); - }; - (@object $object:ident ($($key:tt)+) (:) $copy:tt) => { // "unexpected end of macro invocation" $crate::bson!(); @@ -155,11 +130,6 @@ macro_rules! bson { }; // Misplaced key-value separator. Trigger a reasonable error message. - (@object $object:ident () (=> $($rest:tt)*) ($kv_separator:tt $($copy:tt)*)) => { - // Takes no arguments so "no rules expected the token `=>`". - unimplemented!($kv_separator); - }; - (@object $object:ident () (: $($rest:tt)*) ($kv_separator:tt $($copy:tt)*)) => { // Takes no arguments so "no rules expected the token `:`". unimplemented!($kv_separator); @@ -173,10 +143,6 @@ macro_rules! bson { // Key is fully parenthesized. This avoids clippy double_parens false // positives because the parenthesization may be necessary here. - (@object $object:ident () (($key:expr) => $($rest:tt)*) $copy:tt) => { - $crate::bson!(@object $object ($key) (=> $($rest)*) (=> $($rest)*)); - }; - (@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => { $crate::bson!(@object $object ($key) (: $($rest)*) (: $($rest)*)); }; diff --git a/tests/modules/encoder_decoder.rs b/tests/modules/encoder_decoder.rs index dfe8c8a9..3dc31658 100644 --- a/tests/modules/encoder_decoder.rs +++ b/tests/modules/encoder_decoder.rs @@ -340,7 +340,7 @@ fn test_decode_utc_date_time_overflows() { let decoded = decode_document(&mut Cursor::new(raw)).unwrap(); - let expected = doc! { "A" => Utc.timestamp(1_530_492_218, 999 * 1_000_000)}; + let expected = doc! { "A": Utc.timestamp(1_530_492_218, 999 * 1_000_000)}; assert_eq!(decoded, expected); } @@ -366,7 +366,7 @@ fn test_encode_decode_decimal128() { 26, 0, 0, 0, 19, 107, 101, 121, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 34, 0, ]; - let doc = doc! { "key" => val }; + let doc = doc! { "key": val }; let mut buf = Vec::new(); encode_document(&mut buf, &doc).unwrap(); diff --git a/tests/modules/macros.rs b/tests/modules/macros.rs index 675ff322..205810a4 100644 --- a/tests/modules/macros.rs +++ b/tests/modules/macros.rs @@ -14,7 +14,7 @@ fn standard_format() { let doc = doc! { "float": 2.4, "string": "hello", - "array" => ["testing", 1, true, [1, 2]], + "array": ["testing", 1, true, [1, 2]], "doc": { "fish": "in", "a": "barrel", @@ -47,53 +47,6 @@ fn standard_format() { assert_eq!(expected, format!("{}", doc)); } -// Support rocket format for backwards-compatibility with pre-0.10. -#[test] -fn rocket_format() { - let id_string = "thisismyname"; - let string_bytes: Vec<_> = id_string.bytes().collect(); - let mut bytes = [0; 12]; - bytes[..12].clone_from_slice(&string_bytes[..12]); - - let id = ObjectId::with_bytes(bytes); - let date = Utc::now(); - - let doc = doc! { - "float" => 2.4, - "string" => "hello", - "array" => ["testing", 1, true, ["nested", 2]], - "doc" => { - "fish" => "in", - "a" => "barrel", - "!" => 1, - }, - "bool" => true, - "null" => null, - "regexp" => Bson::Regex(Regex { pattern: "s[ao]d".to_owned(), options: "i".to_owned() }), - "with_wrapped_parens" => (-20), - "code" => Bson::JavaScriptCode("function(x) { return x._id; }".to_owned()), - "i32" => 12, - "i64" => -55, - "timestamp" => Bson::TimeStamp(TimeStamp { time: 0, increment: 229_999_444 }), - "binary" => Binary { subtype: BinarySubtype::Md5, bytes: "thingies".to_owned().into_bytes() }, - "_id" => id, - "date" => Bson::UtcDatetime(date), - }; - - let expected = format!( - "{{ float: 2.4, string: \"hello\", array: [\"testing\", 1, true, [\"nested\", 2]], doc: \ - {{ fish: \"in\", a: \"barrel\", !: 1 }}, bool: true, null: null, regexp: /s[ao]d/i, \ - with_wrapped_parens: -20, code: function(x) {{ return x._id; }}, i32: 12, i64: -55, \ - timestamp: Timestamp(0, 229999444), binary: BinData(5, 0x{}), _id: ObjectId(\"{}\"), \ - date: Date(\"{}\") }}", - hex::encode("thingies"), - hex::encode(id_string), - date - ); - - assert_eq!(expected, format!("{}", doc)); -} - #[test] fn non_trailing_comma() { let doc = doc! { @@ -105,17 +58,6 @@ fn non_trailing_comma() { assert_eq!(expected, format!("{}", doc)); } -#[test] -fn non_trailing_comma_with_rockets() { - let doc = doc! { - "a" => "foo", - "b" => { "ok": "then" } - }; - - let expected = "{ a: \"foo\", b: { ok: \"then\" } }".to_string(); - assert_eq!(expected, format!("{}", doc)); -} - #[test] #[allow(clippy::float_cmp)] fn recursive_macro() {