about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorRaphaƫl Huchet <rap2hpoutre@users.noreply.github.com>2017-05-05 12:02:02 +0200
committerGitHub <noreply@github.com>2017-05-05 12:02:02 +0200
commit68bb5414624d80bec29883c324eb239be73e749d (patch)
tree78564cf7f3424a29a3298da19c16444dcee49d32 /src/libstd
parenta6ab049ed1db09f693df7d33046b3980f56751c1 (diff)
downloadrust-68bb5414624d80bec29883c324eb239be73e749d.tar.gz
rust-68bb5414624d80bec29883c324eb239be73e749d.zip
Add an example to std::thread::Result type
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/thread/mod.rs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs
index 8e7eaa77cd7..2ce5a7262d9 100644
--- a/src/libstd/thread/mod.rs
+++ b/src/libstd/thread/mod.rs
@@ -863,9 +863,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>>;