Add more std::io documentation.
This round: io::Result and the free functions.
This commit is contained in:
@@ -17,11 +17,37 @@ use option::Option::{self, Some, None};
|
||||
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>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user