Skip to content

Commit d84ea8c

Browse files
authored
RUST-343 Remove old doc! macro syntax (#167)
1 parent a676305 commit d84ea8c

File tree

4 files changed

+5
-97
lines changed

4 files changed

+5
-97
lines changed

src/bson.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ impl Bson {
449449
Bson::UtcDatetime(ref v) => {
450450
doc! {
451451
"$date": {
452-
"$numberLong" => (v.timestamp() * 1000) + v.nanosecond() as i64 / 1_000_000,
452+
"$numberLong": (v.timestamp() * 1000) + v.nanosecond() as i64 / 1_000_000,
453453
}
454454
}
455455
}
@@ -461,7 +461,7 @@ impl Bson {
461461
#[cfg(feature = "decimal128")]
462462
Bson::Decimal128(ref v) => {
463463
doc! {
464-
"$numberDecimal" => (v.to_string())
464+
"$numberDecimal": (v.to_string())
465465
}
466466
}
467467
Bson::Undefined => {

src/macros.rs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -92,56 +92,31 @@ macro_rules! bson {
9292
};
9393

9494
// Next value is `null`.
95-
(@object $object:ident ($($key:tt)+) (=> null $($rest:tt)*) $copy:tt) => {
96-
$crate::bson!(@object $object [$($key)+] ($crate::bson!(null)) $($rest)*);
97-
};
98-
9995
(@object $object:ident ($($key:tt)+) (: null $($rest:tt)*) $copy:tt) => {
10096
$crate::bson!(@object $object [$($key)+] ($crate::bson!(null)) $($rest)*);
10197
};
10298

10399
// Next value is an array.
104-
(@object $object:ident ($($key:tt)+) (=> [$($array:tt)*] $($rest:tt)*) $copy:tt) => {
105-
$crate::bson!(@object $object [$($key)+] ($crate::bson!([$($array)*])) $($rest)*);
106-
};
107-
108100
(@object $object:ident ($($key:tt)+) (: [$($array:tt)*] $($rest:tt)*) $copy:tt) => {
109101
$crate::bson!(@object $object [$($key)+] ($crate::bson!([$($array)*])) $($rest)*);
110102
};
111103

112104
// Next value is a map.
113-
(@object $object:ident ($($key:tt)+) (=> {$($map:tt)*} $($rest:tt)*) $copy:tt) => {
114-
$crate::bson!(@object $object [$($key)+] ($crate::bson!({$($map)*})) $($rest)*);
115-
};
116-
117105
(@object $object:ident ($($key:tt)+) (: {$($map:tt)*} $($rest:tt)*) $copy:tt) => {
118106
$crate::bson!(@object $object [$($key)+] ($crate::bson!({$($map)*})) $($rest)*);
119107
};
120108

121109
// Next value is an expression followed by comma.
122-
(@object $object:ident ($($key:tt)+) (=> $value:expr , $($rest:tt)*) $copy:tt) => {
123-
$crate::bson!(@object $object [$($key)+] ($crate::bson!($value)) , $($rest)*);
124-
};
125-
126110
(@object $object:ident ($($key:tt)+) (: $value:expr , $($rest:tt)*) $copy:tt) => {
127111
$crate::bson!(@object $object [$($key)+] ($crate::bson!($value)) , $($rest)*);
128112
};
129113

130114
// Last value is an expression with no trailing comma.
131-
(@object $object:ident ($($key:tt)+) (=> $value:expr) $copy:tt) => {
132-
$crate::bson!(@object $object [$($key)+] ($crate::bson!($value)));
133-
};
134-
135115
(@object $object:ident ($($key:tt)+) (: $value:expr) $copy:tt) => {
136116
$crate::bson!(@object $object [$($key)+] ($crate::bson!($value)));
137117
};
138118

139119
// Missing value for last entry. Trigger a reasonable error message.
140-
(@object $object:ident ($($key:tt)+) (=>) $copy:tt) => {
141-
// "unexpected end of macro invocation"
142-
$crate::bson!();
143-
};
144-
145120
(@object $object:ident ($($key:tt)+) (:) $copy:tt) => {
146121
// "unexpected end of macro invocation"
147122
$crate::bson!();
@@ -155,11 +130,6 @@ macro_rules! bson {
155130
};
156131

157132
// Misplaced key-value separator. Trigger a reasonable error message.
158-
(@object $object:ident () (=> $($rest:tt)*) ($kv_separator:tt $($copy:tt)*)) => {
159-
// Takes no arguments so "no rules expected the token `=>`".
160-
unimplemented!($kv_separator);
161-
};
162-
163133
(@object $object:ident () (: $($rest:tt)*) ($kv_separator:tt $($copy:tt)*)) => {
164134
// Takes no arguments so "no rules expected the token `:`".
165135
unimplemented!($kv_separator);
@@ -173,10 +143,6 @@ macro_rules! bson {
173143

174144
// Key is fully parenthesized. This avoids clippy double_parens false
175145
// positives because the parenthesization may be necessary here.
176-
(@object $object:ident () (($key:expr) => $($rest:tt)*) $copy:tt) => {
177-
$crate::bson!(@object $object ($key) (=> $($rest)*) (=> $($rest)*));
178-
};
179-
180146
(@object $object:ident () (($key:expr) : $($rest:tt)*) $copy:tt) => {
181147
$crate::bson!(@object $object ($key) (: $($rest)*) (: $($rest)*));
182148
};

tests/modules/encoder_decoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ fn test_decode_utc_date_time_overflows() {
340340

341341
let decoded = decode_document(&mut Cursor::new(raw)).unwrap();
342342

343-
let expected = doc! { "A" => Utc.timestamp(1_530_492_218, 999 * 1_000_000)};
343+
let expected = doc! { "A": Utc.timestamp(1_530_492_218, 999 * 1_000_000)};
344344
assert_eq!(decoded, expected);
345345
}
346346

@@ -366,7 +366,7 @@ fn test_encode_decode_decimal128() {
366366
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,
367367
];
368368

369-
let doc = doc! { "key" => val };
369+
let doc = doc! { "key": val };
370370

371371
let mut buf = Vec::new();
372372
encode_document(&mut buf, &doc).unwrap();

tests/modules/macros.rs

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn standard_format() {
1414
let doc = doc! {
1515
"float": 2.4,
1616
"string": "hello",
17-
"array" => ["testing", 1, true, [1, 2]],
17+
"array": ["testing", 1, true, [1, 2]],
1818
"doc": {
1919
"fish": "in",
2020
"a": "barrel",
@@ -47,53 +47,6 @@ fn standard_format() {
4747
assert_eq!(expected, format!("{}", doc));
4848
}
4949

50-
// Support rocket format for backwards-compatibility with pre-0.10.
51-
#[test]
52-
fn rocket_format() {
53-
let id_string = "thisismyname";
54-
let string_bytes: Vec<_> = id_string.bytes().collect();
55-
let mut bytes = [0; 12];
56-
bytes[..12].clone_from_slice(&string_bytes[..12]);
57-
58-
let id = ObjectId::with_bytes(bytes);
59-
let date = Utc::now();
60-
61-
let doc = doc! {
62-
"float" => 2.4,
63-
"string" => "hello",
64-
"array" => ["testing", 1, true, ["nested", 2]],
65-
"doc" => {
66-
"fish" => "in",
67-
"a" => "barrel",
68-
"!" => 1,
69-
},
70-
"bool" => true,
71-
"null" => null,
72-
"regexp" => Bson::Regex(Regex { pattern: "s[ao]d".to_owned(), options: "i".to_owned() }),
73-
"with_wrapped_parens" => (-20),
74-
"code" => Bson::JavaScriptCode("function(x) { return x._id; }".to_owned()),
75-
"i32" => 12,
76-
"i64" => -55,
77-
"timestamp" => Bson::TimeStamp(TimeStamp { time: 0, increment: 229_999_444 }),
78-
"binary" => Binary { subtype: BinarySubtype::Md5, bytes: "thingies".to_owned().into_bytes() },
79-
"_id" => id,
80-
"date" => Bson::UtcDatetime(date),
81-
};
82-
83-
let expected = format!(
84-
"{{ float: 2.4, string: \"hello\", array: [\"testing\", 1, true, [\"nested\", 2]], doc: \
85-
{{ fish: \"in\", a: \"barrel\", !: 1 }}, bool: true, null: null, regexp: /s[ao]d/i, \
86-
with_wrapped_parens: -20, code: function(x) {{ return x._id; }}, i32: 12, i64: -55, \
87-
timestamp: Timestamp(0, 229999444), binary: BinData(5, 0x{}), _id: ObjectId(\"{}\"), \
88-
date: Date(\"{}\") }}",
89-
hex::encode("thingies"),
90-
hex::encode(id_string),
91-
date
92-
);
93-
94-
assert_eq!(expected, format!("{}", doc));
95-
}
96-
9750
#[test]
9851
fn non_trailing_comma() {
9952
let doc = doc! {
@@ -105,17 +58,6 @@ fn non_trailing_comma() {
10558
assert_eq!(expected, format!("{}", doc));
10659
}
10760

108-
#[test]
109-
fn non_trailing_comma_with_rockets() {
110-
let doc = doc! {
111-
"a" => "foo",
112-
"b" => { "ok": "then" }
113-
};
114-
115-
let expected = "{ a: \"foo\", b: { ok: \"then\" } }".to_string();
116-
assert_eq!(expected, format!("{}", doc));
117-
}
118-
11961
#[test]
12062
#[allow(clippy::float_cmp)]
12163
fn recursive_macro() {

0 commit comments

Comments
 (0)