Add missing example for Display::fmt#40299
Merged
bors merged 1 commit intorust-lang:masterfrom Mar 12, 2017
Merged
Conversation
frewsxcv
reviewed
Mar 7, 2017
src/libcore/fmt/mod.rs
Outdated
Contributor
There was a problem hiding this comment.
This is slightly confusing because it looks like a Debug representation. How do you feel about getting rid of the Foo:: in the outputted string?
Member
Author
There was a problem hiding this comment.
I always add the enum's name first in case you have multiple wrappings:
enum Foo {
A,
}
enum X {
A(Foo),
}
enum Y {
A(X),
}
Contributor
There was a problem hiding this comment.
I think you're mixing up Debug and Display. Display is for user-facing output. Users shouldn't care about enum namespacing. We don't want to encourage Rust developers to implement Display if their types aren't mean to be displayed to end-users.
How about this as the example:
struct Position {
longitude: f32,
latitude: f32,
}
impl fmt::Display for Position {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "({}, {})", self.longitude, self.latitude)
}
}This seems a little more realistic than Foo and Bar and Stack ;)
8628d0a to
a5a3981
Compare
Member
Author
|
Updated. |
Contributor
|
@bors r+ rollup |
Collaborator
|
📌 Commit a5a3981 has been approved by |
arielb1
pushed a commit
to arielb1/rust
that referenced
this pull request
Mar 11, 2017
… r=frewsxcv Add missing example for Display::fmt r? @frewsxcv
arielb1
pushed a commit
to arielb1/rust
that referenced
this pull request
Mar 11, 2017
… r=frewsxcv Add missing example for Display::fmt r? @frewsxcv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
r? @frewsxcv