From cf8e1fee1619b29fb1d9a355f28a9f992426dd5a Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Thu, 25 Aug 2016 16:20:21 -0400 Subject: [PATCH] add a simple example for `thread::current()` --- src/libstd/thread/mod.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index f06c105d30e65..42260cf195ffa 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -322,6 +322,24 @@ pub fn spawn(f: F) -> JoinHandle where } /// Gets a handle to the thread that invokes it. +/// +/// #Examples +/// +/// Getting a handle to the current thread with `thread::current()`: +/// +/// ``` +/// use std::thread; +/// +/// let handler = thread::Builder::new() +/// .name("named thread".into()) +/// .spawn(|| { +/// let handle = thread::current(); +/// assert_eq!(handle.name(), Some("named thread")); +/// }) +/// .unwrap(); +/// +/// handler.join().unwrap(); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn current() -> Thread { thread_info::current_thread().expect("use of std::thread::current() is not \