Skip to content

Commit 68bb541

Browse files
authored
Add an example to std::thread::Result type
1 parent a6ab049 commit 68bb541

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/libstd/thread/mod.rs

+22
Original file line numberDiff line numberDiff line change
@@ -863,9 +863,31 @@ impl fmt::Debug for Thread {
863863
// JoinHandle
864864
////////////////////////////////////////////////////////////////////////////////
865865

866+
/// A specialized [`Result`] type for threads.
867+
///
866868
/// Indicates the manner in which a thread exited.
867869
///
868870
/// A thread that completes without panicking is considered to exit successfully.
871+
///
872+
/// # Examples
873+
///
874+
/// ```no_run
875+
/// use std::thread;
876+
/// use std::fs;
877+
///
878+
/// fn copy_in_thread() -> thread::Result<()> {
879+
/// thread::spawn(move || { fs::copy("foo.txt", "bar.txt").unwrap(); }).join()
880+
/// }
881+
///
882+
/// fn main() {
883+
/// match copy_in_thread() {
884+
/// Ok(_) => println!("this is fine"),
885+
/// Err(_) => println!("thread panicked"),
886+
/// }
887+
/// }
888+
/// ```
889+
///
890+
/// [`Result`]: ../../std/result/enum.Result.html
869891
#[stable(feature = "rust1", since = "1.0.0")]
870892
pub type Result<T> = ::result::Result<T, Box<Any + Send + 'static>>;
871893

0 commit comments

Comments
 (0)