]> 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 95ae6ebfb68c30b9ad26a0cb1fd2b7fa5d75d588..c3d49e24978455c5ab75a0c66cf6ab2e14723c25 100644 (file)
 //! drop(file);
 //! ```
 //!
-//! If you *do* write that in Rust, the compiler will by give you a
+//! If you *do* write that in Rust, the compiler will give you a
 //! warning (by default, controlled by the `unused_must_use` lint).
 //!
 //! You might instead, if you don't want to handle the error, simply
 //! 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};
@@ -383,8 +379,8 @@ pub fn as_ref(&self) -> Result<&T, &E> {
     /// ```
     /// fn mutate(r: &mut Result<int, int>) {
     ///     match r.as_mut() {
-    ///         Ok(&ref mut v) => *v = 42,
-    ///         Err(&ref mut e) => *e = 0,
+    ///         Ok(&mut ref mut v) => *v = 42,
+    ///         Err(&mut ref mut e) => *e = 0,
     ///     }
     /// }
     ///
@@ -529,7 +525,7 @@ pub fn iter(&self) -> Iter<T> {
     /// ```
     /// let mut x: Result<uint, &str> = Ok(7);
     /// match x.iter_mut().next() {
-    ///     Some(&ref mut x) => *x = 40,
+    ///     Some(&mut ref mut x) => *x = 40,
     ///     None => {},
     /// }
     /// assert_eq!(x, Ok(40));
@@ -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
         }
     }
@@ -953,7 +949,7 @@ fn next(&mut self) -> Option<T> {
 /// If an `Err` is encountered, it is immediately returned.
 /// Otherwise, the folded value is returned.
 #[inline]
-#[experimental]
+#[unstable]
 pub fn fold<T,
             V,
             E,