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 @@ -507,6 +507,37 @@ impl Thread {
507
507
}
508
508
509
509
/// Gets the thread's name.
510
+ ///
511
+ /// # Examples
512
+ ///
513
+ /// Threads by default have no name specified:
514
+ ///
515
+ /// ```
516
+ /// use std::thread;
517
+ ///
518
+ /// let builder = thread::Builder::new();
519
+ ///
520
+ /// let handler = builder.spawn(|| {
521
+ /// assert!(thread::current().name().is_none());
522
+ /// }).unwrap();
523
+ ///
524
+ /// handler.join().unwrap();
525
+ /// ```
526
+ ///
527
+ /// Thread with a specified name:
528
+ ///
529
+ /// ```
530
+ /// use std::thread;
531
+ ///
532
+ /// let builder = thread::Builder::new()
533
+ /// .name("foo".into());
534
+ ///
535
+ /// let handler = builder.spawn(|| {
536
+ /// assert_eq!(thread::current().name(), Some("foo"))
537
+ /// }).unwrap();
538
+ ///
539
+ /// handler.join().unwrap();
540
+ /// ```
510
541
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
511
542
pub fn name ( & self ) -> Option < & str > {
512
543
self . cname ( ) . map ( |s| unsafe { str:: from_utf8_unchecked ( s. to_bytes ( ) ) } )
You can’t perform that action at this time.
0 commit comments