Skip to content

Support static string as key value#486

Merged
KodrAus merged 1 commit into
rust-lang:masterfrom
Thomasdezeeuw:issue#484
Mar 2, 2022
Merged

Support static string as key value#486
KodrAus merged 1 commit into
rust-lang:masterfrom
Thomasdezeeuw:issue#484

Conversation

@Thomasdezeeuw
Copy link
Copy Markdown
Collaborator

Fixes #484.

@Thomasdezeeuw
Copy link
Copy Markdown
Collaborator Author

Thomasdezeeuw commented Feb 25, 2022

@KodrAus this was a lot easier then I expected, so I'm a little worried I'm forgetting about a use case I'm breaking.

Comment thread src/macros.rs
macro_rules! log {
// log!(target: "my_target", Level::Info; key1 = 42, key2 = true; "a {} event", "log");
(target: $target:expr, $lvl:expr, $($key:ident = $value:expr),+; $($arg:tt)+) => ({
(target: $target:expr, $lvl:expr, $($key:tt = $value:expr),+; $($arg:tt)+) => ({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh unfortunately I think this will include quotes in string keys. So for "string/key" the actual string we get will look like "\"string/key\"".

Looking at this again though, I don't think we actually need a tt muncher yet afterall. We can just use another macro around __log_stringify! (or just re-use __log_stringify! for it) that matches on literals and idents and handles them appropriately.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, this means the tests I've added are also flawed as they should have caught this.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KodrAus
Copy link
Copy Markdown
Contributor

KodrAus commented Feb 26, 2022

@Thomasdezeeuw I'll still push ahead with 0.4.15 in its current state, but once we're ready with this one we can do a 0.4.16. It would be good to get back into the habit of more regular releases here anyways.

@KodrAus
Copy link
Copy Markdown
Contributor

KodrAus commented Mar 2, 2022

Just an update for you @Thomasdezeeuw. Turns out my permissions to the repo aren't fully sorted yet so I can't actually do any publishing. Just working to get that sorted so I think we probably will be able to fit this in.

Copy link
Copy Markdown
Contributor

@KodrAus KodrAus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me!

@KodrAus KodrAus merged commit 863c461 into rust-lang:master Mar 2, 2022
@Thomasdezeeuw Thomasdezeeuw deleted the issue#484 branch March 3, 2022 13:07
EFanZh pushed a commit to EFanZh/log that referenced this pull request Jul 23, 2023
Bumps [cargo_toml](https://gitlab.com/crates.rs/cargo_toml) from 0.12.4 to 0.13.0.
- [Release notes](https://gitlab.com/crates.rs/cargo_toml/tags)
- [Commits](https://gitlab.com/crates.rs/cargo_toml/commits/master)

---
updated-dependencies:
- dependency-name: cargo_toml
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow static string to be used as key in macros

2 participants