diff options
| author | bors <bors@rust-lang.org> | 2016-06-21 16:14:38 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-06-21 16:14:38 -0700 |
| commit | b8deebe3d678dcc65dce713e894544e234f1c474 (patch) | |
| tree | 4f28b25e8fd567833c85761a58208d4298874e41 /src/libstd/thread | |
| parent | fe96928d7de991e527a7ed7b88bb30aa965c8a08 (diff) | |
| parent | 0db65750bc5e0f2ded19fa32ecc791aaf3dd1536 (diff) | |
| download | rust-b8deebe3d678dcc65dce713e894544e234f1c474.tar.gz rust-b8deebe3d678dcc65dce713e894544e234f1c474.zip | |
Auto merge of #34402 - GuillaumeGomez:rollup, r=GuillaumeGomez
Rollup of 7 pull requests - Successful merges: #34356, #34360, #34369, #34371, #34378, #34380, #34391 - Failed merges:
Diffstat (limited to 'src/libstd/thread')
| -rw-r--r-- | src/libstd/thread/mod.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index c474aa60b3e..1f78b32bcf3 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -507,6 +507,37 @@ impl Thread { } /// Gets the thread's name. + /// + /// # Examples + /// + /// Threads by default have no name specified: + /// + /// ``` + /// use std::thread; + /// + /// let builder = thread::Builder::new(); + /// + /// let handler = builder.spawn(|| { + /// assert!(thread::current().name().is_none()); + /// }).unwrap(); + /// + /// handler.join().unwrap(); + /// ``` + /// + /// Thread with a specified name: + /// + /// ``` + /// use std::thread; + /// + /// let builder = thread::Builder::new() + /// .name("foo".into()); + /// + /// let handler = builder.spawn(|| { + /// assert_eq!(thread::current().name(), Some("foo")) + /// }).unwrap(); + /// + /// handler.join().unwrap(); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn name(&self) -> Option<&str> { self.cname().map(|s| unsafe { str::from_utf8_unchecked(s.to_bytes()) } ) |
