about summary refs log tree commit diff
path: root/src/libcore/fmt
diff options
context:
space:
mode:
authorRyan Thomas <ryan@ryant.org>2017-06-22 21:10:36 +0100
committerRyan Thomas <ryan@ryant.org>2017-07-13 17:24:28 +0100
commitaca6cd052d51a16f09b1e9a6051a746d0ff2ce85 (patch)
tree0ad84b313fca48f3e91fe6b1b377f6350c34a332 /src/libcore/fmt
parentab5bec25530aac43dfd64384b405c909b6e405e3 (diff)
downloadrust-aca6cd052d51a16f09b1e9a6051a746d0ff2ce85.tar.gz
rust-aca6cd052d51a16f09b1e9a6051a746d0ff2ce85.zip
Update docs on Error struct. #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
Diffstat (limited to 'src/libcore/fmt')
-rw-r--r--src/libcore/fmt/mod.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs
index 8c3d3ce7d88..d7c3cd4d3d9 100644
--- a/src/libcore/fmt/mod.rs
+++ b/src/libcore/fmt/mod.rs
@@ -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;