Skip to content

Commit 8aad3a3

Browse files
committed
Auto merge of #41768 - rap2hpoutre:patch-4, r=frewsxcv
Add an example to std::thread::Result type This PR is a part of #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
2 parents 42a4f37 + 71aaab1 commit 8aad3a3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Diff for: src/libstd/thread/mod.rs

+22
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,31 @@ impl fmt::Debug for Thread {
865865
// JoinHandle
866866
////////////////////////////////////////////////////////////////////////////////
867867

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

0 commit comments

Comments
 (0)