@@ -749,7 +749,7 @@ impl<T> JoinInner<T> {
749
749
///
750
750
/// A `JoinHandle` *detaches* the child thread when it is dropped.
751
751
///
752
- /// Due to platform restrictions, it is not possible to `Clone` this
752
+ /// Due to platform restrictions, it is not possible to [ `Clone`] this
753
753
/// handle: the ability to join a child thread is a uniquely-owned
754
754
/// permission.
755
755
///
@@ -760,7 +760,7 @@ impl<T> JoinInner<T> {
760
760
///
761
761
/// Creation from [`thread::spawn`]:
762
762
///
763
- /// ```rust
763
+ /// ```
764
764
/// use std::thread;
765
765
///
766
766
/// let join_handle: thread::JoinHandle<_> = thread::spawn(|| {
@@ -770,7 +770,7 @@ impl<T> JoinInner<T> {
770
770
///
771
771
/// Creation from [`thread::Builder::spawn`]:
772
772
///
773
- /// ```rust
773
+ /// ```
774
774
/// use std::thread;
775
775
///
776
776
/// let builder = thread::Builder::new();
@@ -780,22 +780,56 @@ impl<T> JoinInner<T> {
780
780
/// }).unwrap();
781
781
/// ```
782
782
///
783
+ /// [`Clone`]: ../../std/clone/trait.Clone.html
783
784
/// [`thread::spawn`]: fn.spawn.html
784
785
/// [`thread::Builder::spawn`]: struct.Builder.html#method.spawn
785
786
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
786
787
pub struct JoinHandle < T > ( JoinInner < T > ) ;
787
788
788
789
impl < T > JoinHandle < T > {
789
- /// Extracts a handle to the underlying thread
790
+ /// Extracts a handle to the underlying thread.
791
+ ///
792
+ /// # Examples
793
+ ///
794
+ /// ```
795
+ /// #![feature(thread_id)]
796
+ ///
797
+ /// use std::thread;
798
+ ///
799
+ /// let builder = thread::Builder::new();
800
+ ///
801
+ /// let join_handle: thread::JoinHandle<_> = builder.spawn(|| {
802
+ /// // some work here
803
+ /// }).unwrap();
804
+ ///
805
+ /// let thread = join_handle.thread();
806
+ /// println!("thread id: {:?}", thread.id());
807
+ /// ```
790
808
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
791
809
pub fn thread ( & self ) -> & Thread {
792
810
& self . 0 . thread
793
811
}
794
812
795
813
/// Waits for the associated thread to finish.
796
814
///
797
- /// If the child thread panics, `Err` is returned with the parameter given
798
- /// to `panic`.
815
+ /// If the child thread panics, [`Err`] is returned with the parameter given
816
+ /// to [`panic`].
817
+ ///
818
+ /// [`Err`]: ../../std/result/enum.Result.html#variant.Err
819
+ /// [`panic!`]: ../../std/macro.panic.html
820
+ ///
821
+ /// # Examples
822
+ ///
823
+ /// ```
824
+ /// use std::thread;
825
+ ///
826
+ /// let builder = thread::Builder::new();
827
+ ///
828
+ /// let join_handle: thread::JoinHandle<_> = builder.spawn(|| {
829
+ /// // some work here
830
+ /// }).unwrap();
831
+ /// join_handle.join().expect("Couldn't join on the associated thread");
832
+ /// ```
799
833
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
800
834
pub fn join ( mut self ) -> Result < T > {
801
835
self . 0 . join ( )
0 commit comments