3
3
/// Construct a bson::BSON value from a literal.
4
4
///
5
5
/// ```rust
6
- /// # #[macro_use]
7
- /// # extern crate bson;
6
+ /// # use bson::bson;
8
7
/// #
9
8
/// # fn main() {
10
9
/// let value = bson!({
@@ -40,32 +39,32 @@ macro_rules! bson {
40
39
41
40
// Next element is `null`.
42
41
( @array [ $( $elems: expr, ) * ] null $( $rest: tt) * ) => {
43
- bson!( @array [ $( $elems, ) * bson!( null) ] $( $rest) * )
42
+ $crate :: bson!( @array [ $( $elems, ) * $crate :: bson!( null) ] $( $rest) * )
44
43
} ;
45
44
46
45
// Next element is an array.
47
46
( @array [ $( $elems: expr, ) * ] [ $( $array: tt) * ] $( $rest: tt) * ) => {
48
- bson!( @array [ $( $elems, ) * bson!( [ $( $array) * ] ) ] $( $rest) * )
47
+ $crate :: bson!( @array [ $( $elems, ) * $crate :: bson!( [ $( $array) * ] ) ] $( $rest) * )
49
48
} ;
50
49
51
50
// Next element is a map.
52
51
( @array [ $( $elems: expr, ) * ] { $( $map: tt) * } $( $rest: tt) * ) => {
53
- bson!( @array [ $( $elems, ) * bson!( { $( $map) * } ) ] $( $rest) * )
52
+ $crate :: bson!( @array [ $( $elems, ) * $crate :: bson!( { $( $map) * } ) ] $( $rest) * )
54
53
} ;
55
54
56
55
// Next element is an expression followed by comma.
57
56
( @array [ $( $elems: expr, ) * ] $next: expr, $( $rest: tt) * ) => {
58
- bson!( @array [ $( $elems, ) * bson!( $next) , ] $( $rest) * )
57
+ $crate :: bson!( @array [ $( $elems, ) * $crate :: bson!( $next) , ] $( $rest) * )
59
58
} ;
60
59
61
60
// Last element is an expression with no trailing comma.
62
61
( @array [ $( $elems: expr, ) * ] $last: expr) => {
63
- bson!( @array [ $( $elems, ) * bson!( $last) ] )
62
+ $crate :: bson!( @array [ $( $elems, ) * $crate :: bson!( $last) ] )
64
63
} ;
65
64
66
65
// Comma after the most recent element.
67
66
( @array [ $( $elems: expr) ,* ] , $( $rest: tt) * ) => {
68
- bson!( @array [ $( $elems, ) * ] $( $rest) * )
67
+ $crate :: bson!( @array [ $( $elems, ) * ] $( $rest) * )
69
68
} ;
70
69
71
70
//////////////////////////////////////////////////////////////////////////
@@ -84,7 +83,7 @@ macro_rules! bson {
84
83
// Insert the current entry followed by trailing comma.
85
84
( @object $object: ident [ $( $key: tt) +] ( $value: expr) , $( $rest: tt) * ) => {
86
85
$object. insert_bson( ( $( $key) +) . into( ) , $value) ;
87
- bson!( @object $object ( ) ( $( $rest) * ) ( $( $rest) * ) ) ;
86
+ $crate :: bson!( @object $object ( ) ( $( $rest) * ) ( $( $rest) * ) ) ;
88
87
} ;
89
88
90
89
// Insert the last entry without trailing comma.
@@ -94,65 +93,65 @@ macro_rules! bson {
94
93
95
94
// Next value is `null`.
96
95
( @object $object: ident ( $( $key: tt) +) ( => null $( $rest: tt) * ) $copy: tt) => {
97
- bson!( @object $object [ $( $key) +] ( bson!( null) ) $( $rest) * ) ;
96
+ $crate :: bson!( @object $object [ $( $key) +] ( $crate :: bson!( null) ) $( $rest) * ) ;
98
97
} ;
99
98
100
99
( @object $object: ident ( $( $key: tt) +) ( : null $( $rest: tt) * ) $copy: tt) => {
101
- bson!( @object $object [ $( $key) +] ( bson!( null) ) $( $rest) * ) ;
100
+ $crate :: bson!( @object $object [ $( $key) +] ( $crate :: bson!( null) ) $( $rest) * ) ;
102
101
} ;
103
102
104
103
// Next value is an array.
105
104
( @object $object: ident ( $( $key: tt) +) ( => [ $( $array: tt) * ] $( $rest: tt) * ) $copy: tt) => {
106
- bson!( @object $object [ $( $key) +] ( bson!( [ $( $array) * ] ) ) $( $rest) * ) ;
105
+ $crate :: bson!( @object $object [ $( $key) +] ( $crate :: bson!( [ $( $array) * ] ) ) $( $rest) * ) ;
107
106
} ;
108
107
109
108
( @object $object: ident ( $( $key: tt) +) ( : [ $( $array: tt) * ] $( $rest: tt) * ) $copy: tt) => {
110
- bson!( @object $object [ $( $key) +] ( bson!( [ $( $array) * ] ) ) $( $rest) * ) ;
109
+ $crate :: bson!( @object $object [ $( $key) +] ( $crate :: bson!( [ $( $array) * ] ) ) $( $rest) * ) ;
111
110
} ;
112
111
113
112
// Next value is a map.
114
113
( @object $object: ident ( $( $key: tt) +) ( => { $( $map: tt) * } $( $rest: tt) * ) $copy: tt) => {
115
- bson!( @object $object [ $( $key) +] ( bson!( { $( $map) * } ) ) $( $rest) * ) ;
114
+ $crate :: bson!( @object $object [ $( $key) +] ( $crate :: bson!( { $( $map) * } ) ) $( $rest) * ) ;
116
115
} ;
117
116
118
117
( @object $object: ident ( $( $key: tt) +) ( : { $( $map: tt) * } $( $rest: tt) * ) $copy: tt) => {
119
- bson!( @object $object [ $( $key) +] ( bson!( { $( $map) * } ) ) $( $rest) * ) ;
118
+ $crate :: bson!( @object $object [ $( $key) +] ( $crate :: bson!( { $( $map) * } ) ) $( $rest) * ) ;
120
119
} ;
121
120
122
121
// Next value is an expression followed by comma.
123
122
( @object $object: ident ( $( $key: tt) +) ( => $value: expr , $( $rest: tt) * ) $copy: tt) => {
124
- bson!( @object $object [ $( $key) +] ( bson!( $value) ) , $( $rest) * ) ;
123
+ $crate :: bson!( @object $object [ $( $key) +] ( $crate :: bson!( $value) ) , $( $rest) * ) ;
125
124
} ;
126
125
127
126
( @object $object: ident ( $( $key: tt) +) ( : $value: expr , $( $rest: tt) * ) $copy: tt) => {
128
- bson!( @object $object [ $( $key) +] ( bson!( $value) ) , $( $rest) * ) ;
127
+ $crate :: bson!( @object $object [ $( $key) +] ( $crate :: bson!( $value) ) , $( $rest) * ) ;
129
128
} ;
130
129
131
130
// Last value is an expression with no trailing comma.
132
131
( @object $object: ident ( $( $key: tt) +) ( => $value: expr) $copy: tt) => {
133
- bson!( @object $object [ $( $key) +] ( bson!( $value) ) ) ;
132
+ $crate :: bson!( @object $object [ $( $key) +] ( $crate :: bson!( $value) ) ) ;
134
133
} ;
135
134
136
135
( @object $object: ident ( $( $key: tt) +) ( : $value: expr) $copy: tt) => {
137
- bson!( @object $object [ $( $key) +] ( bson!( $value) ) ) ;
136
+ $crate :: bson!( @object $object [ $( $key) +] ( $crate :: bson!( $value) ) ) ;
138
137
} ;
139
138
140
139
// Missing value for last entry. Trigger a reasonable error message.
141
140
( @object $object: ident ( $( $key: tt) +) ( =>) $copy: tt) => {
142
141
// "unexpected end of macro invocation"
143
- bson!( ) ;
142
+ $crate :: bson!( ) ;
144
143
} ;
145
144
146
145
( @object $object: ident ( $( $key: tt) +) ( : ) $copy: tt) => {
147
146
// "unexpected end of macro invocation"
148
- bson!( ) ;
147
+ $crate :: bson!( ) ;
149
148
} ;
150
149
151
150
// Missing key-value separator and value for last entry.
152
151
// Trigger a reasonable error message.
153
152
( @object $object: ident ( $( $key: tt) +) ( ) $copy: tt) => {
154
153
// "unexpected end of macro invocation"
155
- bson!( ) ;
154
+ $crate :: bson!( ) ;
156
155
} ;
157
156
158
157
// Misplaced key-value separator. Trigger a reasonable error message.
@@ -175,16 +174,16 @@ macro_rules! bson {
175
174
// Key is fully parenthesized. This avoids clippy double_parens false
176
175
// positives because the parenthesization may be necessary here.
177
176
( @object $object: ident ( ) ( ( $key: expr) => $( $rest: tt) * ) $copy: tt) => {
178
- bson!( @object $object ( $key) ( => $( $rest) * ) ( => $( $rest) * ) ) ;
177
+ $crate :: bson!( @object $object ( $key) ( => $( $rest) * ) ( => $( $rest) * ) ) ;
179
178
} ;
180
179
181
180
( @object $object: ident ( ) ( ( $key: expr) : $( $rest: tt) * ) $copy: tt) => {
182
- bson!( @object $object ( $key) ( : $( $rest) * ) ( : $( $rest) * ) ) ;
181
+ $crate :: bson!( @object $object ( $key) ( : $( $rest) * ) ( : $( $rest) * ) ) ;
183
182
} ;
184
183
185
184
// Munch a token into the current key.
186
185
( @object $object: ident ( $( $key: tt) * ) ( $tt: tt $( $rest: tt) * ) $copy: tt) => {
187
- bson!( @object $object ( $( $key) * $tt) ( $( $rest) * ) ( $( $rest) * ) ) ;
186
+ $crate :: bson!( @object $object ( $( $key) * $tt) ( $( $rest) * ) ( $( $rest) * ) ) ;
188
187
} ;
189
188
190
189
//////////////////////////////////////////////////////////////////////////
@@ -202,15 +201,15 @@ macro_rules! bson {
202
201
} ;
203
202
204
203
( [ $( $tt: tt) + ] ) => {
205
- $crate:: Bson :: Array ( bson!( @array [ ] $( $tt) +) )
204
+ $crate:: Bson :: Array ( $crate :: bson!( @array [ ] $( $tt) +) )
206
205
} ;
207
206
208
207
( { } ) => {
209
- $crate:: Bson :: Document ( doc!{ } )
208
+ $crate:: Bson :: Document ( $crate :: doc!{ } )
210
209
} ;
211
210
212
211
( { $( $tt: tt) +} ) => {
213
- $crate:: Bson :: Document ( doc!{ $( $tt) +} ) ;
212
+ $crate:: Bson :: Document ( $crate :: doc!{ $( $tt) +} ) ;
214
213
} ;
215
214
216
215
// Any Serialize type: numbers, strings, struct literals, variables etc.
@@ -223,8 +222,7 @@ macro_rules! bson {
223
222
/// Construct a bson::Document value.
224
223
///
225
224
/// ```rust
226
- /// # #[macro_use]
227
- /// # extern crate bson;
225
+ /// # use bson::doc;
228
226
/// #
229
227
/// # fn main() {
230
228
/// let value = doc! {
@@ -244,7 +242,7 @@ macro_rules! doc {
244
242
( ) => { { $crate:: Document :: new( ) } } ;
245
243
( $( $tt: tt) + ) => { {
246
244
let mut object = $crate:: Document :: new( ) ;
247
- bson!( @object object ( ) ( $( $tt) +) ( $( $tt) +) ) ;
245
+ $crate :: bson!( @object object ( ) ( $( $tt) +) ( $( $tt) +) ) ;
248
246
object
249
247
} } ;
250
248
}
0 commit comments