1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
#[macro_export] macro_rules! bson { ([]) => {{ $crate::Bson::Array(Vec::new()) }}; ([$($val:tt),*]) => {{ let mut array = Vec::new(); $( array.push(bson!($val)); )* $crate::Bson::Array(array) }}; ([$val:expr]) => {{ $crate::Bson::Array(vec!(::std::convert::From::from($val))) }}; ({ $($k:expr => $v:tt),* }) => {{ $crate::Bson::Document(doc! { $( $k => $v ),* }) }}; ($val:expr) => {{ ::std::convert::From::from($val) }}; } #[macro_export] macro_rules! doc { () => {{ $crate::Document::new() }}; ( $($key:expr => $val:tt),* ) => {{ let mut document = $crate::Document::new(); $( document.insert_bson($key.to_owned(), bson!($val)); )* document }}; }