Skip to content
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

Switch log macro syntax to allow logging expressions #383

Closed
austinabell opened this issue Apr 28, 2021 · 1 comment
Closed

Switch log macro syntax to allow logging expressions #383

austinabell opened this issue Apr 28, 2021 · 1 comment

Comments

@austinabell
Copy link
Contributor

Opening this issue to open discussion on what would be the best path for the log macro.

I preemptively made the change to allow the macro to accept expressions for single argument usages in #366 because I believe it is not breaking and only allows additional usage, but I didn't consider if it was intentionally similar to what is used for std::format.

The difference is that the current functionality, just like the format! macro, does not allow for expressions for single argument usages.

The alternative, which might be more familiar to anyone who has used the log crate, is allowing expressions to be provided as a single argument, which gives any user a cleaner experience.

Without the change, a simple example such as:

let s: String = "test".to_string();
log!(s);

Requires that the string is required to be moved because you cannot take a reference manually or through a function with the :tt syntax.

With the change, which is just changing the arg type to expr, allows the following:

let s: String = "test".to_string();
log!(&s);
log!(s.as_str());

println!("I can still use {}", s);

I think this can be done as a non-breaking change and can open it up in a separate PR from #366, which is for sure a breaking change, but let me know what you guys think!

@austinabell
Copy link
Contributor Author

this was done

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

No branches or pull requests

1 participant