]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #41768 - rap2hpoutre:patch-4, r=frewsxcv
authorbors <bors@rust-lang.org>
Sat, 6 May 2017 02:01:00 +0000 (02:01 +0000)
committerbors <bors@rust-lang.org>
Sat, 6 May 2017 02:01:00 +0000 (02:01 +0000)
Add an example to std::thread::Result type

This PR is a part of https://github.com/rust-lang/rust/issues/29378. I submit this PR with the help (mentoring) of @steveklabnik. I'm still not sure my request is good enough but I don't want to spoil the issue with too much questions so I continue here. r? @steveklabnik

1  2 
src/libstd/thread/mod.rs

diff --combined src/libstd/thread/mod.rs
index 9cded2ab28911ea209d343a398d3288cbf3a3ad9,279fe0376d29dcaddda5d54300399b460bfe7937..4cbcfdbc2d7f677d5c44f232d508c41f6965de5a
@@@ -723,9 -723,7 +723,9 @@@ struct Inner 
  ///
  /// # Examples
  ///
 -/// ```
 +/// ```no_run
 +/// # // Note that this example isn't executed by default because it causes
 +/// # // deadlocks on Windows unfortunately (see #25824)
  /// use std::thread::Builder;
  ///
  /// for i in 0..5 {
@@@ -865,9 -863,31 +865,31 @@@ impl fmt::Debug for Thread 
  // JoinHandle
  ////////////////////////////////////////////////////////////////////////////////
  
+ /// A specialized [`Result`] type for threads.
+ ///
  /// Indicates the manner in which a thread exited.
  ///
  /// A thread that completes without panicking is considered to exit successfully.
+ ///
+ /// # Examples
+ ///
+ /// ```no_run
+ /// use std::thread;
+ /// use std::fs;
+ ///
+ /// fn copy_in_thread() -> thread::Result<()> {
+ ///     thread::spawn(move || { fs::copy("foo.txt", "bar.txt").unwrap(); }).join()
+ /// }
+ ///
+ /// fn main() {
+ ///     match copy_in_thread() {
+ ///         Ok(_) => println!("this is fine"),
+ ///         Err(_) => println!("thread panicked"),
+ ///     }
+ /// }
+ /// ```
+ ///
+ /// [`Result`]: ../../std/result/enum.Result.html
  #[stable(feature = "rust1", since = "1.0.0")]
  pub type Result<T> = ::result::Result<T, Box<Any + Send + 'static>>;