Skip to content

Commit cf52121

Browse files
author
Christian Poveda
committed
restructured docs for thread and added links
1 parent bdb6bb9 commit cf52121

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/libstd/thread/mod.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -713,28 +713,34 @@ struct Inner {
713713

714714
#[derive(Clone)]
715715
#[stable(feature = "rust1", since = "1.0.0")]
716-
/// A handle to a thread, its just an abstract reference and as such
717-
/// it can be used to identify a thread (by name, for example). In most
718-
/// usage cases, this struct is not used directly.
716+
/// A handle to a thread.
717+
///
718+
/// You can use it to identify a thread (by name, for example). Most of the
719+
/// time, there is no need to directly create a `Thread` struct using the
720+
/// constructor, instead you should use a function like `spawn` to create
721+
/// new threads, see the docs of [`Builder`] and [`spawn`] for more.
719722
///
720723
/// # Examples
721724
///
722725
/// ```
723-
/// use std::thread;
726+
/// use std::thread::Builder;
724727
///
725728
/// for i in 0..5 {
726729
/// let thread_name = format!("thread_{}", i);
727-
/// thread::Builder::new()
728-
/// .name(thread_name) // Now you can identify which thread panicked
729-
/// // thanks to the handle's name
730-
/// .spawn(move || {
731-
/// if i == 3 {
732-
/// panic!("I'm scared!!!");
733-
/// }
734-
/// })
735-
/// .unwrap();
730+
/// Builder::new()
731+
/// .name(thread_name) // Now you can identify which thread panicked
732+
/// // thanks to the handle's name
733+
/// .spawn(move || {
734+
/// if i == 3 {
735+
/// panic!("I'm scared!!!");
736+
/// }
737+
/// })
738+
/// .unwrap();
736739
/// }
737740
/// ```
741+
/// [`Builder`]: ../../std/thread/struct.Builder.html
742+
/// [`spawn`]: ../../std/thread/fn.spawn.html
743+
738744
pub struct Thread {
739745
inner: Arc<Inner>,
740746
}

0 commit comments

Comments
 (0)