File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -478,6 +478,37 @@ impl Thread {
478478 }
479479
480480 /// Gets the thread's name.
481+ ///
482+ /// # Examples
483+ ///
484+ /// Threads by default have no name specified:
485+ ///
486+ /// ```
487+ /// use std::thread;
488+ ///
489+ /// let builder = thread::Builder::new();
490+ ///
491+ /// let handler = builder.spawn(|| {
492+ /// assert!(thread::current().name().is_none());
493+ /// }).unwrap();
494+ ///
495+ /// handler.join().unwrap();
496+ /// ```
497+ ///
498+ /// Thread with a specified name:
499+ ///
500+ /// ```
501+ /// use std::thread;
502+ ///
503+ /// let builder = thread::Builder::new()
504+ /// .name("foo".into());
505+ ///
506+ /// let handler = builder.spawn(|| {
507+ /// assert_eq!(thread::current().name(), Some("foo"))
508+ /// }).unwrap();
509+ ///
510+ /// handler.join().unwrap();
511+ /// ```
481512 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
482513 pub fn name ( & self ) -> Option < & str > {
483514 self . cname ( ) . map ( |s| unsafe { str:: from_utf8_unchecked ( s. to_bytes ( ) ) } )
You can’t perform that action at this time.
0 commit comments