]> git.lizzy.rs Git - rust.git/commitdiff
add a simple example for `thread::current()`
authorMatthew Piziak <matthew.piziak@gmail.com>
Thu, 25 Aug 2016 20:20:21 +0000 (16:20 -0400)
committerMatthew Piziak <matthew.piziak@gmail.com>
Thu, 25 Aug 2016 20:20:21 +0000 (16:20 -0400)
src/libstd/thread/mod.rs

index f06c105d30e6500eee11e92e8f8c73ecdd4c07ff..42260cf195ffa3de2c6498924ed9b0669db94fcf 100644 (file)
@@ -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 \