@@ -784,7 +784,7 @@ impl<T> JoinInner<T> {
784
784
///
785
785
/// A `JoinHandle` *detaches* the child thread when it is dropped.
786
786
///
787
- /// Due to platform restrictions, it is not possible to `Clone` this
787
+ /// Due to platform restrictions, it is not possible to [ `Clone`] this
788
788
/// handle: the ability to join a child thread is a uniquely-owned
789
789
/// permission.
790
790
///
@@ -795,7 +795,7 @@ impl<T> JoinInner<T> {
795
795
///
796
796
/// Creation from [`thread::spawn`]:
797
797
///
798
- /// ```rust
798
+ /// ```
799
799
/// use std::thread;
800
800
///
801
801
/// let join_handle: thread::JoinHandle<_> = thread::spawn(|| {
@@ -805,7 +805,7 @@ impl<T> JoinInner<T> {
805
805
///
806
806
/// Creation from [`thread::Builder::spawn`]:
807
807
///
808
- /// ```rust
808
+ /// ```
809
809
/// use std::thread;
810
810
///
811
811
/// let builder = thread::Builder::new();
@@ -815,22 +815,56 @@ impl<T> JoinInner<T> {
815
815
/// }).unwrap();
816
816
/// ```
817
817
///
818
+ /// [`Clone`]: ../../std/clone/trait.Clone.html
818
819
/// [`thread::spawn`]: fn.spawn.html
819
820
/// [`thread::Builder::spawn`]: struct.Builder.html#method.spawn
820
821
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
821
822
pub struct JoinHandle < T > ( JoinInner < T > ) ;
822
823
823
824
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
+ /// ```
825
843
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
826
844
pub fn thread ( & self ) -> & Thread {
827
845
& self . 0 . thread
828
846
}
829
847
830
848
/// Waits for the associated thread to finish.
831
849
///
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
+ /// ```
834
868
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
835
869
pub fn join ( mut self ) -> Result < T > {
836
870
self . 0 . join ( )
0 commit comments