File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -320,6 +320,24 @@ pub fn spawn<F, T>(f: F) -> JoinHandle<T> where
320320}
321321
322322/// 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+ /// ```
323341#[ stable( feature = "rust1" , since = "1.0.0" ) ]
324342pub fn current ( ) -> Thread {
325343 thread_info:: current_thread ( ) . expect ( "use of std::thread::current() is not \
You can’t perform that action at this time.
0 commit comments