about summary refs log tree commit diff
path: root/src/libstd/thread
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2016-08-30 10:39:07 +0200
committerGitHub <noreply@github.com>2016-08-30 10:39:07 +0200
commit23f769881ac4aa7b8b06006cf632b35bd3adb62d (patch)
tree50acadcb91e8768095dcd90eae70cc49bf050672 /src/libstd/thread
parent0c33197b909999321fb273da6e12bc0a7bd763e9 (diff)
parentcf8e1fee1619b29fb1d9a355f28a9f992426dd5a (diff)
downloadrust-23f769881ac4aa7b8b06006cf632b35bd3adb62d.tar.gz
rust-23f769881ac4aa7b8b06006cf632b35bd3adb62d.zip
Rollup merge of #35997 - matthew-piziak:thread-current-example, r=GuillaumeGomez
add a simple example for `thread::current()`

r? @GuillaumeGomez
Diffstat (limited to 'src/libstd/thread')
-rw-r--r--src/libstd/thread/mod.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs
index f3e1710f50b..e3f3f9dd6de 100644
--- a/src/libstd/thread/mod.rs
+++ b/src/libstd/thread/mod.rs
@@ -320,6 +320,24 @@ pub fn spawn<F, T>(f: F) -> JoinHandle<T> 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 \