We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
thread::current()
1 parent 528c6f3 commit cf8e1feCopy full SHA for cf8e1fe
src/libstd/thread/mod.rs
@@ -322,6 +322,24 @@ pub fn spawn<F, T>(f: F) -> JoinHandle<T> where
322
}
323
324
/// Gets a handle to the thread that invokes it.
325
+///
326
+/// #Examples
327
328
+/// Getting a handle to the current thread with `thread::current()`:
329
330
+/// ```
331
+/// use std::thread;
332
333
+/// let handler = thread::Builder::new()
334
+/// .name("named thread".into())
335
+/// .spawn(|| {
336
+/// let handle = thread::current();
337
+/// assert_eq!(handle.name(), Some("named thread"));
338
+/// })
339
+/// .unwrap();
340
341
+/// handler.join().unwrap();
342
343
#[stable(feature = "rust1", since = "1.0.0")]
344
pub fn current() -> Thread {
345
thread_info::current_thread().expect("use of std::thread::current() is not \
0 commit comments