Skip to content

Commit fe810e9

Browse files
committed
better rawdoc
1 parent b63cd15 commit fe810e9

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/macros.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,19 +291,26 @@ macro_rules! rawbson {
291291
// Finished.
292292
(@object $object:ident () () ()) => {};
293293

294-
// Insert the current entry followed by trailing comma.
294+
// Insert the current entry with followed by trailing comma, with a key literal.
295+
(@object $object:ident [$key:literal] ($value:expr) , $($rest:tt)*) => {{
296+
$object.append($crate::raw::cstr!($key), $value);
297+
$crate::rawbson!(@object $object () ($($rest)*) ($($rest)*));
298+
}};
299+
300+
// Insert the current entry with followed by trailing comma, with a key expression.
295301
(@object $object:ident [$($key:tt)+] ($value:expr) , $($rest:tt)*) => {{
296-
let key: &str = ($($key)+).as_ref();
297-
let key: &$crate::raw::CStr = key.try_into().expect("invalid key");
298-
$object.append(key, $value);
302+
$object.append($($key)+, $value);
299303
$crate::rawbson!(@object $object () ($($rest)*) ($($rest)*));
300304
}};
301305

302-
// Insert the last entry without trailing comma.
306+
// Insert the last entry without trailing comma, with a key literal.
307+
(@object $object:ident [$key:literal] ($value:expr)) => {
308+
$object.append($crate::raw::cstr!($key), $value);
309+
};
310+
311+
// Insert the last entry without trailing comma, with a key expression.
303312
(@object $object:ident [$($key:tt)+] ($value:expr)) => {
304-
let key: &str = ($($key)+).as_ref();
305-
let key: &$crate::raw::CStr = key.try_into().expect("invalid key");
306-
$object.append(key, $value);
313+
$object.append($($key)+, $value);
307314
};
308315

309316
// Next value is `null`.

0 commit comments

Comments
 (0)