Skip to content

Commit b83285b

Browse files
Rollup merge of rust-lang#42837 - rthomas:29355-error, r=steveklabnik
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
2 parents 83c659e + aca6cd0 commit b83285b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/libcore/fmt/mod.rs

+16
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ pub type Result = result::Result<(), Error>;
8181
/// This type does not support transmission of an error other than that an error
8282
/// occurred. Any extra information must be arranged to be transmitted through
8383
/// some other means.
84+
///
85+
/// An important thing to remember is that the type `fmt::Error` should not be
86+
/// confused with `std::io::Error` or `std::error::Error`, which you may also
87+
/// have in scope.
88+
///
89+
/// # Examples
90+
///
91+
/// ```rust
92+
/// use std::fmt::{self, write};
93+
///
94+
/// let mut output = String::new();
95+
/// match write(&mut output, format_args!("Hello {}!", "world")) {
96+
/// Err(fmt::Error) => panic!("An error occurred"),
97+
/// _ => (),
98+
/// }
99+
/// ```
84100
#[stable(feature = "rust1", since = "1.0.0")]
85101
#[derive(Copy, Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
86102
pub struct Error;

0 commit comments

Comments
 (0)