-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Update docs on Error struct. #29355 #42837
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @steveklabnik (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. Due to 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 the contribution instructions for more information. |
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.
some nits. I agree that the example is not spectacular, but I have no better suggestions right now, and so it's fine.
src/libcore/fmt/mod.rs
Outdated
@@ -81,6 +81,21 @@ pub type Result = result::Result<(), Error>; | |||
/// This type does not support transmission of an error other than that an error | |||
/// occurred. Any extra information must be arranged to be transmitted through | |||
/// some other means. | |||
/// | |||
/// The key thing to remember here is that the type `fmt::Error` should not be |
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.
I would say "An important thing to remember is" instead, that is, this is very important, but not the thing, IMO
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.
Done.
src/libcore/fmt/mod.rs
Outdated
/// # Example | ||
/// | ||
/// ```rust | ||
/// use std::fmt; |
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.
use std::fmt{self, write};
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.
Done.
src/libcore/fmt/mod.rs
Outdated
/// use std::fmt; | ||
/// | ||
/// let mut output = String::new(); | ||
/// match fmt::write(&mut output, format_args!("Hello {}!", "world")) { |
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.
match write
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.
Done.
src/libcore/fmt/mod.rs
Outdated
/// match fmt::write(&mut output, format_args!("Hello {}!", "world")) { | ||
/// Err(fmt::Error) => panic!("An error occurred"), | ||
/// _ => (), | ||
/// } |
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.
instead of match, using unwrap_or_else
is more idiomatic here
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.
I agree it would be more idiomatic, but that would not demonstrate the usage of fmt::Error
- so I'm not sure if it would be worth including the example in that case.
src/libcore/fmt/mod.rs
Outdated
@@ -81,6 +81,21 @@ pub type Result = result::Result<(), Error>; | |||
/// This type does not support transmission of an error other than that an error | |||
/// occurred. Any extra information must be arranged to be transmitted through | |||
/// some other means. | |||
/// | |||
/// The key thing to remember here is that the type `fmt::Error` should not be | |||
/// confused with `std::error::Error`, which you may also have in scope. |
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.
If we're comparing to other Error
s within the standard library, it might also be good to include std::io::Error
, which I would consider more well-known than the Error trait.
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.
Done.
I've pushed up a commit with the review comments addressed in it. The only potentially open issue is the example. |
Friendly ping. |
Sorry about this! I took Monday of work to get a four-day weekend 😄 I will review this later today. |
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.
Hi! Sorry again. Two extremely tiny nits, and then let's . Ping me once they're changed and I will merge post-haste!
src/libcore/fmt/mod.rs
Outdated
@@ -1,3 +1,4 @@ | |||
|
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.
can you remove this please?
src/libcore/fmt/mod.rs
Outdated
/// confused with `std::io::Error` or `std::error::Error`, which you may also | ||
/// have in scope. | ||
/// | ||
/// # Example |
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 should be Examples
even though there's only one, for consistency.
Thanks @steveklabnik I've fixed up the issues and pushed the commit up - would you like me to squash them down or are they fine as is? |
@steveklabnik friendly ping. |
@rthomas sorry, somehow I missed this! Yeah, if you could squash, that'd be great. Happy to merge after 😄 |
This adds a pretty contrived example of the usage of fmt::Error. I am very open to suggestions for a better one. I have also highlighted the fmt::Error vs std::error::Error. r? @steveklabnik
Thanks @steveklabnik, I have squashed the commits. |
@steveklabnik looks like this is ready for your r! |
@bors: r+ rollup thanks so much, and sorry again about the delays |
📌 Commit aca6cd0 has been approved by |
Update docs on Error struct. rust-lang#29355 This adds a pretty contrived example of the usage of fmt::Error. I am very open to suggestions for a better one. I have also highlighted the fmt::Error vs std::error::Error. r? @steveklabnik
This adds a pretty contrived example of the usage of fmt::Error. I am
very open to suggestions for a better one.
I have also highlighted the fmt::Error vs std::error::Error.
r? @steveklabnik