diff options
| author | bors <bors@rust-lang.org> | 2016-07-12 03:58:33 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-07-12 03:58:33 -0700 |
| commit | 31e9ed5d6cf567557d2219add7afedae93aaf2a5 (patch) | |
| tree | 532d8e1dd03867f528770c6e0dbf426266d4b28f /src/libstd | |
| parent | 5c69a4f619fb4f71f2497f7ee4a25a34a374da4d (diff) | |
| parent | 23d5f5652c9297643ed149634c245eaf9967a871 (diff) | |
| download | rust-31e9ed5d6cf567557d2219add7afedae93aaf2a5.tar.gz rust-31e9ed5d6cf567557d2219add7afedae93aaf2a5.zip | |
Auto merge of #34778 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 7 pull requests - Successful merges: #34736, #34737, #34740, #34742, #34749, #34750, #34770 - Failed merges: #33951
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/error.rs | 70 | ||||
| -rw-r--r-- | src/libstd/process.rs | 40 |
2 files changed, 99 insertions, 11 deletions
diff --git a/src/libstd/error.rs b/src/libstd/error.rs index 2a2d41112ff..1459420cdc0 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -66,10 +66,80 @@ pub trait Error: Debug + Display + Reflect { /// The description should not contain newlines or sentence-ending /// punctuation, to facilitate embedding in larger user-facing /// strings. + /// + /// # Examples + /// + /// ``` + /// use std::error::Error; + /// + /// match "xc".parse::<u32>() { + /// Err(e) => { + /// println!("Error: {}", e.description()); + /// } + /// _ => println!("No error"), + /// } + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn description(&self) -> &str; /// The lower-level cause of this error, if any. + /// + /// # Examples + /// + /// ``` + /// use std::error::Error; + /// use std::fmt; + /// + /// #[derive(Debug)] + /// struct SuperError { + /// side: SuperErrorSideKick, + /// } + /// + /// impl fmt::Display for SuperError { + /// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + /// write!(f, "SuperError is here!") + /// } + /// } + /// + /// impl Error for SuperError { + /// fn description(&self) -> &str { + /// "I'm the superhero of errors!" + /// } + /// + /// fn cause(&self) -> Option<&Error> { + /// Some(&self.side) + /// } + /// } + /// + /// #[derive(Debug)] + /// struct SuperErrorSideKick; + /// + /// impl fmt::Display for SuperErrorSideKick { + /// fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + /// write!(f, "SuperErrorSideKick is here!") + /// } + /// } + /// + /// impl Error for SuperErrorSideKick { + /// fn description(&self) -> &str { + /// "I'm SuperError side kick!" + /// } + /// } + /// + /// fn get_super_error() -> Result<(), SuperError> { + /// Err(SuperError { side: SuperErrorSideKick }) + /// } + /// + /// fn main() { + /// match get_super_error() { + /// Err(e) => { + /// println!("Error: {}", e.description()); + /// println!("Caused by: {}", e.cause().unwrap()); + /// } + /// _ => println!("No error"), + /// } + /// } + /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn cause(&self) -> Option<&Error> { None } diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 2edd1a30638..16bc81de78e 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -27,8 +27,9 @@ use sys_common::{AsInner, AsInnerMut, FromInner, IntoInner}; /// Representation of a running or exited child process. /// /// This structure is used to represent and manage child processes. A child -/// process is created via the `Command` struct, which configures the spawning -/// process and can itself be constructed using a builder-style interface. +/// process is created via the [`Command`] struct, which configures the +/// spawning process and can itself be constructed using a builder-style +/// interface. /// /// # Examples /// @@ -48,13 +49,18 @@ use sys_common::{AsInner, AsInnerMut, FromInner, IntoInner}; /// /// # Note /// -/// Take note that there is no implementation of -/// [`Drop`](../../core/ops/trait.Drop.html) for child processes, so if you -/// do not ensure the `Child` has exited then it will continue to run, even -/// after the `Child` handle to the child process has gone out of scope. +/// Take note that there is no implementation of [`Drop`] for child processes, +/// so if you do not ensure the `Child` has exited then it will continue to +/// run, even after the `Child` handle to the child process has gone out of +/// scope. /// -/// Calling `wait` (or other functions that wrap around it) will make the -/// parent process wait until the child has actually exited before continuing. +/// Calling [`wait`][`wait`] (or other functions that wrap around it) will make +/// the parent process wait until the child has actually exited before +/// continuing. +/// +/// [`Command`]: struct.Command.html +/// [`Drop`]: ../../core/ops/trait.Drop.html +/// [`wait`]: #method.wait #[stable(feature = "process", since = "1.0.0")] pub struct Child { handle: imp::Process, @@ -91,7 +97,11 @@ impl IntoInner<imp::Process> for Child { fn into_inner(self) -> imp::Process { self.handle } } -/// A handle to a child process's stdin +/// A handle to a child process's stdin. This struct is used in the [`stdin`] +/// field on [`Child`]. +/// +/// [`Child`]: struct.Child.html +/// [`stdin`]: struct.Child.html#structfield.stdin #[stable(feature = "process", since = "1.0.0")] pub struct ChildStdin { inner: AnonPipe @@ -122,7 +132,11 @@ impl FromInner<AnonPipe> for ChildStdin { } } -/// A handle to a child process's stdout +/// A handle to a child process's stdout. This struct is used in the [`stdout`] +/// field on [`Child`]. +/// +/// [`Child`]: struct.Child.html +/// [`stdout`]: struct.Child.html#structfield.stdout #[stable(feature = "process", since = "1.0.0")] pub struct ChildStdout { inner: AnonPipe @@ -152,7 +166,11 @@ impl FromInner<AnonPipe> for ChildStdout { } } -/// A handle to a child process's stderr +/// A handle to a child process's stderr. This struct is used in the [`stderr`] +/// field on [`Child`]. +/// +/// [`Child`]: struct.Child.html +/// [`stderr`]: struct.Child.html#structfield.stderr #[stable(feature = "process", since = "1.0.0")] pub struct ChildStderr { inner: AnonPipe |
