-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: Statically enforce Unicode in std::fmt #526
Conversation
Statically enforce that the `std::fmt` module can only create valid UTF-8 data by removing the arbitrary `write` method in favor of a `write_str` method.
cc @SimonSapin |
👍 |
I think it’s fine for this trait to be in |
I seem to remember from way back when I was working on the base64 and hex modules that |
I'd probably be more in favor of an unsafe function to go from |
@sfackler Looks like Also, if the char/byte is literal, how does |
|
||
```rust | ||
pub trait Writer { | ||
fn write_str(&mut self, data: &str) -> Result; |
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.
Doesn't Result need to be instantiated?
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.
This is std::fmt::Result
.
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 ok, thanks. I somehow missed that one looking for other Result
s.
@SimonSapin I'd imagine that'd help, but I ran into this like ~1.5 years ago so my memory's a bit rusty :) @alexcrichton Yeah, implementations just transmuting from |
@sfackler You can always used |
Could it be confusing for newcomers for the stdlib to have two traits called Writer? Having to check to see which is in use, etc. |
@Sgeo I think we more or less have a convention to take advantage of the namespacing provided by modules and not try to duplicate it within names. Rather than have |
This RFC, which represents a longstanding request to enforce a strong Unicode convention and appears to have no real downsides, has been accepted. Tracking issue. |
I notice that in the "after" benchmark, |
Statically enforce that the
std::fmt
module can only create valid UTF-8 databy removing the arbitrary
write
method in favor of awrite_str
method.Rendered