Skip to content

Commit df63b0c

Browse files
authored
Rollup merge of #38572 - GuillaumeGomez:join_handle_docs, r=frewsxcv
Add JoinHandle missing examples r? @frewsxcv
2 parents 637818f + 00645e8 commit df63b0c

File tree

1 file changed

+40
-6
lines changed

1 file changed

+40
-6
lines changed

src/libstd/thread/mod.rs

+40-6
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ impl<T> JoinInner<T> {
784784
///
785785
/// A `JoinHandle` *detaches* the child thread when it is dropped.
786786
///
787-
/// Due to platform restrictions, it is not possible to `Clone` this
787+
/// Due to platform restrictions, it is not possible to [`Clone`] this
788788
/// handle: the ability to join a child thread is a uniquely-owned
789789
/// permission.
790790
///
@@ -795,7 +795,7 @@ impl<T> JoinInner<T> {
795795
///
796796
/// Creation from [`thread::spawn`]:
797797
///
798-
/// ```rust
798+
/// ```
799799
/// use std::thread;
800800
///
801801
/// let join_handle: thread::JoinHandle<_> = thread::spawn(|| {
@@ -805,7 +805,7 @@ impl<T> JoinInner<T> {
805805
///
806806
/// Creation from [`thread::Builder::spawn`]:
807807
///
808-
/// ```rust
808+
/// ```
809809
/// use std::thread;
810810
///
811811
/// let builder = thread::Builder::new();
@@ -815,22 +815,56 @@ impl<T> JoinInner<T> {
815815
/// }).unwrap();
816816
/// ```
817817
///
818+
/// [`Clone`]: ../../std/clone/trait.Clone.html
818819
/// [`thread::spawn`]: fn.spawn.html
819820
/// [`thread::Builder::spawn`]: struct.Builder.html#method.spawn
820821
#[stable(feature = "rust1", since = "1.0.0")]
821822
pub struct JoinHandle<T>(JoinInner<T>);
822823

823824
impl<T> JoinHandle<T> {
824-
/// Extracts a handle to the underlying thread
825+
/// Extracts a handle to the underlying thread.
826+
///
827+
/// # Examples
828+
///
829+
/// ```
830+
/// #![feature(thread_id)]
831+
///
832+
/// use std::thread;
833+
///
834+
/// let builder = thread::Builder::new();
835+
///
836+
/// let join_handle: thread::JoinHandle<_> = builder.spawn(|| {
837+
/// // some work here
838+
/// }).unwrap();
839+
///
840+
/// let thread = join_handle.thread();
841+
/// println!("thread id: {:?}", thread.id());
842+
/// ```
825843
#[stable(feature = "rust1", since = "1.0.0")]
826844
pub fn thread(&self) -> &Thread {
827845
&self.0.thread
828846
}
829847

830848
/// Waits for the associated thread to finish.
831849
///
832-
/// If the child thread panics, `Err` is returned with the parameter given
833-
/// to `panic`.
850+
/// If the child thread panics, [`Err`] is returned with the parameter given
851+
/// to [`panic`].
852+
///
853+
/// [`Err`]: ../../std/result/enum.Result.html#variant.Err
854+
/// [`panic!`]: ../../std/macro.panic.html
855+
///
856+
/// # Examples
857+
///
858+
/// ```
859+
/// use std::thread;
860+
///
861+
/// let builder = thread::Builder::new();
862+
///
863+
/// let join_handle: thread::JoinHandle<_> = builder.spawn(|| {
864+
/// // some work here
865+
/// }).unwrap();
866+
/// join_handle.join().expect("Couldn't join on the associated thread");
867+
/// ```
834868
#[stable(feature = "rust1", since = "1.0.0")]
835869
pub fn join(mut self) -> Result<T> {
836870
self.0.join()

0 commit comments

Comments
 (0)