use result;
use sys;
-/// A type for results generated by I/O related functions where the `Err` type
-/// is hard-wired to `io::Error`.
+/// A specialized [`Result`][result] type for I/O operations.
+///
+/// [result]: ../result/enum.Result.html
+///
+/// This type is broadly used across `std::io` for any operation which may
+/// produce an error.
///
/// This typedef is generally used to avoid writing out `io::Error` directly and
-/// is otherwise a direct mapping to `std::result::Result`.
+/// is otherwise a direct mapping to `Result`.
+///
+/// While usual Rust style is to import types directly, aliases of `Result`
+/// often are not, to make it easier to distinguish between them. `Result` is
+/// generally assumed to be `std::result::Result`, and so users of this alias
+/// will generally use `io::Result` instead of shadowing the prelude's import
+/// of `std::result::Result`.
+///
+/// # Examples
+///
+/// A convenience function that bubbles an `io::Result` to its caller:
+///
+/// ```
+/// use std::io;
+///
+/// fn get_string() -> io::Result<String> {
+/// let mut buffer = String::new();
+///
+/// try!(io::stdin().read_line(&mut buffer));
+///
+/// Ok(buffer)
+/// }
+/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub type Result<T> = result::Result<T, Error>;
///
/// If this `Error` was constructed via `new` then this function will
/// return `Some`, otherwise it will return `None`.
- #[unstable(feature = "io_error_inner",
- reason = "recently added and requires UFCS to downcast")]
+ #[stable(feature = "io_error_inner", since = "1.3.0")]
pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> {
match self.repr {
Repr::Os(..) => None,
///
/// If this `Error` was constructed via `new` then this function will
/// return `Some`, otherwise it will return `None`.
- #[unstable(feature = "io_error_inner",
- reason = "recently added and requires UFCS to downcast")]
+ #[stable(feature = "io_error_inner", since = "1.3.0")]
pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> {
match self.repr {
Repr::Os(..) => None,
///
/// If this `Error` was constructed via `new` then this function will
/// return `Some`, otherwise it will return `None`.
- #[unstable(feature = "io_error_inner",
- reason = "recently added and requires UFCS to downcast")]
+ #[stable(feature = "io_error_inner", since = "1.3.0")]
pub fn into_inner(self) -> Option<Box<error::Error+Send+Sync>> {
match self.repr {
Repr::Os(..) => None,
// we have to call all of these UFCS style right now since method
// resolution won't implicitly drop the Send+Sync bounds
let mut err = Error::new(ErrorKind::Other, TestError);
- assert!(error::Error::is::<TestError>(err.get_ref().unwrap()));
+ assert!(err.get_ref().unwrap().is::<TestError>());
assert_eq!("asdf", err.get_ref().unwrap().description());
- assert!(error::Error::is::<TestError>(err.get_mut().unwrap()));
+ assert!(err.get_mut().unwrap().is::<TestError>());
let extracted = err.into_inner().unwrap();
- error::Error::downcast::<TestError>(extracted).unwrap();
+ extracted.downcast::<TestError>().unwrap();
}
}