]> git.lizzy.rs Git - rust.git/blobdiff - src/libcore/result.rs
std: Rename Show/String to Debug/Display
[rust.git] / src / libcore / result.rs
index 373291b031e8a18905304dafbcd97fc092da53eb..c3d49e24978455c5ab75a0c66cf6ab2e14723c25 100644 (file)
 //! fn write_info(info: &Info) -> Result<(), IoError> {
 //!     let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write);
 //!     // Early return on error
-//!     match file.write_line(format!("name: {}", info.name).as_slice()) {
-//!         Ok(_) => (),
-//!         Err(e) => return Err(e)
+//!     if let Err(e) = file.write_line(format!("name: {}", info.name).as_slice()) {
+//!         return Err(e)
 //!     }
-//!     match file.write_line(format!("age: {}", info.age).as_slice()) {
-//!         Ok(_) => (),
-//!         Err(e) => return Err(e)
+//!     if let Err(e) = file.write_line(format!("age: {}", info.age).as_slice()) {
+//!         return Err(e)
 //!     }
 //!     return file.write_line(format!("rating: {}", info.rating).as_slice());
 //! }
 //! makes it clear:
 //!
 //! ```
-//! # #![feature(macro_rules)]
 //! macro_rules! try {
 //!     ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) })
 //! }
-//! # fn main() { }
 //! ```
 //!
 //! `try!` is imported by the prelude, and is available everywhere.
 use self::Result::{Ok, Err};
 
 use clone::Clone;
-use fmt::Show;
+use fmt::Display;
 use iter::{Iterator, IteratorExt, DoubleEndedIterator, FromIterator, ExactSizeIterator};
 use ops::{FnMut, FnOnce};
 use option::Option::{self, None, Some};
@@ -718,7 +714,7 @@ pub fn unwrap_or_else<F: FnOnce(E) -> T>(self, op: F) -> T {
 }
 
 #[stable]
-impl<T, E: Show> Result<T, E> {
+impl<T, E: Display> Result<T, E> {
     /// Unwraps a result, yielding the content of an `Ok`.
     ///
     /// # Panics
@@ -743,13 +739,13 @@ pub fn unwrap(self) -> T {
         match self {
             Ok(t) => t,
             Err(e) =>
-                panic!("called `Result::unwrap()` on an `Err` value: {:?}", e)
+                panic!("called `Result::unwrap()` on an `Err` value: {}", e)
         }
     }
 }
 
 #[stable]
-impl<T: Show, E> Result<T, E> {
+impl<T: Display, E> Result<T, E> {
     /// Unwraps a result, yielding the content of an `Err`.
     ///
     /// # Panics
@@ -773,7 +769,7 @@ impl<T: Show, E> Result<T, E> {
     pub fn unwrap_err(self) -> E {
         match self {
             Ok(t) =>
-                panic!("called `Result::unwrap_err()` on an `Ok` value: {:?}", t),
+                panic!("called `Result::unwrap_err()` on an `Ok` value: {}", t),
             Err(e) => e
         }
     }