-
Notifications
You must be signed in to change notification settings - Fork 147
Improve macro syntax support #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only glossed over the macro implementation itself, as it's not worth blocking this for the amount of time it would take me to actually understand all of it
@@ -397,19 +397,19 @@ impl Bson { | |||
match *self { | |||
Bson::RegExp(ref pat, ref opt) => { | |||
doc! { | |||
"$regex" => (pat.clone()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm so confused about git saying the first ')' was removed here but the second below
src/bson.rs
Outdated
@@ -397,19 +397,19 @@ impl Bson { | |||
match *self { | |||
Bson::RegExp(ref pat, ref opt) => { | |||
doc! { | |||
"$regex" => (pat.clone()), | |||
"$options" => (opt.clone()) | |||
"$regex" => pat.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, why remove the parens/add trailing commas but not switch the "=>" to ":"? Is this a rustfmt thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, just made these changes before I re-added colon support. i'll change these.
/// # | ||
/// # fn main() { | ||
/// let value = bson!({ | ||
/// "code": 200, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to document the "=>" syntax, or are we considering that discouraged (but kept around for compatibility)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering it discouraged in favor of consistency, but here for backwards-compatibility.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good
#[macro_export] | ||
macro_rules! bson { | ||
([]) => {{ $crate::Bson::Array(Vec::new()) }}; | ||
////////////////////////////////////////////////////////////////////////// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume these comments are also lifted from serde_json?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah; not sure where the line falls in terms of fair usage.
tests/lib.rs
Outdated
"doc" => { | ||
"fish" => "in", | ||
"a" => "barrel", | ||
"!" => 1 | ||
"!" => 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the trailing comma required? If not, we should probably add a separate test for without it (both nested and top-level)
tests/lib.rs
Outdated
"doc": { | ||
"fish": "in", | ||
"a": "barrel", | ||
"!": 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto above about additional tests for without trailing commas
LGTM |
@zonyitoo ready for a publish. thanks 🙏 |
Published v0.10.0 |
What
Overhauls the bson/doc macro definitions to support syntactic sugar available in the
json!
macro:.
charactersnull
keywordHow
By taking serde's
json!
macro and making a couple changes (including overloaded support for rocket separators for backwards-compatibility), and some simplifications (removing redundant boolean cases, etc). I ran the mongo driver tests with this branch ofbson
and they all passed, which is convincing enough for me (along with our bson-rs tests) that we don't have any regressions.Who
@zonyitoo, @saghm