-
Notifications
You must be signed in to change notification settings - Fork 20
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
Implement From<&'a &'static str>
for Arguments<'a>
#257
Comments
I'd go further and go for a conversion or constructor from (I haven't made any progress on rust-lang/rust#99012 lately, but I will look into making conversion from |
Did exactly that in rust-lang/rust#115129 I'm still tweaking things a bit for performance, but it's looking good. :) |
Ideally, that wouldn't be the case. I think we can, eventually, make |
Both this API and |
@Zoxc What do you mean? You don't see a reason for these APIs to exist, or you don't see a reason for certain restrictions? Which restrictions do you mean? |
I mean the APIs place restrictions on the implementation of This proposal seems want to pass a The existence for |
We discussed this in the libs-api meeting. We don't feel comfortable adding a stable Feel free to open a tracking issue and open a PR to rust-lang/rust to add this as an unstable function on fmt::Arguments. |
Proposal
Problem statement
Implement
From<&'a &'static str>
forArguments<'a>
.Motivating examples or use cases
The
log!
macro from thelog
crate once had an optimization for calls with a string literal, but later the optimization was removed to support capturing variables in log messages (see rust-lang/log#446).The idea is that constructing an
Arguments
object is more costly than constructing an&str
object, so in order to reduce the binary size, thelog!
macro could dispatch the call to two different functions based on whether the message is a string literal:I intend to bring that optimization back, the problem is that although we can construct an
Arguments
object from an&str
object usingformat_args!("{s}")
, the resultArguments
object won’t has itsas_str
method returningSome(&'static str)
, which essentially prevents logging backend from utilizingas_str
.Solution sketch
The standard library provides a way to construct an
Arguments
object that returnsSome(&'static str)
if called on itsas_str()
method from an&'static str
object. I think implementingFrom<&'a &'static str>
forArguments<'a>
seems to be a reasonable thing to do this.Alternatives
The only thing I think of is utilizing private API
Arguments::new_const
, but it’s not a good idea.Links and related work
Implementation PR: rust-lang/rust#114531
What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
Second, if there's a concrete solution:
The text was updated successfully, but these errors were encountered: