-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add a write_char method to std::fmt::Formatter. #24689
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
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. The way Github handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see CONTRIBUTING.md for more information. |
Hm can you clarify why you'd want this as an inherent method? It seems like a similar win is gained from implementing |
I only made it an inherent method because I don’t have a strong opinion on how to do this, or if it should be done at all. |
I think it would be safe to provide an implementation of the trait for |
@SimonSapin could you try adding this method through an implementation of the |
This is the logical next step after rust-lang#24661, but I’m less sure about this one.
b3c46d0
to
10fbce3
Compare
Done. (Now the trait has to be in scope to use that method, of course.) |
@@ -892,6 +892,20 @@ impl<'a> Formatter<'a> { | |||
} | |||
} | |||
|
|||
impl<'a> Write for Formatter<'a> { |
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.
Could you also tag this with #[stable(since = "1.2.0", ...)]
?
r=me with a stability tag, thanks @SimonSapin! |
10fbce3
to
63da18b
Compare
This is the logical next step after #24661, but I’m less sure about this one. r? @alexcrichton
let mut utf8 = [0; 4]; | ||
let amt = self.encode_utf8(&mut utf8).unwrap_or(0); | ||
let s: &str = unsafe { mem::transmute(&utf8[..amt]) }; | ||
Display::fmt(s, f) |
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.
Ah, yes, my mistake. Feel free to reverse this chunk if there isn’t a better solution.
This recently regressed in rust-lang#24689, and this updates the `Display` implementation to take formatting flags into account. Closes rust-lang#26625
This recently regressed in rust-lang#24689, and this updates the `Display` implementation to take formatting flags into account. Closes rust-lang#26625
This is the logical next step after #24661, but I’m less sure about this one.
r? @alexcrichton