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 @@ -322,6 +322,24 @@ pub fn spawn<F, T>(f: F) -> JoinHandle<T> where
322322}
323323
324324/// 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+ /// ```
325343#[ stable( feature = "rust1" , since = "1.0.0" ) ]
326344pub fn current ( ) -> Thread {
327345 thread_info:: current_thread ( ) . expect ( "use of std::thread::current() is not \
You can’t perform that action at this time.
0 commit comments