about summary refs log tree commit diff
path: root/src/libstd/thread
diff options
context:
space:
mode:
authorMatthew Piziak <matthew.piziak@gmail.com>2016-08-25 16:20:21 -0400
committerMatthew Piziak <matthew.piziak@gmail.com>2016-08-25 16:20:21 -0400
commitcf8e1fee1619b29fb1d9a355f28a9f992426dd5a (patch)
tree01b38de19f78d8b0df8bfda5794656ba791d3830 /src/libstd/thread
parent528c6f3ed6a23a374dc5a40582d1bea2f2cfda65 (diff)
downloadrust-cf8e1fee1619b29fb1d9a355f28a9f992426dd5a.tar.gz
rust-cf8e1fee1619b29fb1d9a355f28a9f992426dd5a.zip
add a simple example for `thread::current()`
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 f06c105d30e..42260cf195f 100644
--- a/src/libstd/thread/mod.rs
+++ b/src/libstd/thread/mod.rs
@@ -322,6 +322,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 \