Skip to content

Commit

Permalink
Update docs on Error struct. rust-lang#29355
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rthomas committed Jul 13, 2017
1 parent ab5bec2 commit aca6cd0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ 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.
///
/// An important thing to remember is that the type `fmt::Error` should not be
/// confused with `std::io::Error` or `std::error::Error`, which you may also
/// have in scope.
///
/// # Examples
///
/// ```rust
/// use std::fmt::{self, write};
///
/// let mut output = String::new();
/// match write(&mut output, format_args!("Hello {}!", "world")) {
/// Err(fmt::Error) => panic!("An error occurred"),
/// _ => (),
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct Error;
Expand Down

0 comments on commit aca6cd0

Please sign in to comment.