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