diff options
| author | Corey Farwell <coreyf@rwell.org> | 2016-06-19 17:51:35 -0400 |
|---|---|---|
| committer | Corey Farwell <coreyf@rwell.org> | 2016-06-19 17:55:57 -0400 |
| commit | d5a27594a3abeee9a8c81cc016dfb3a5b8b51d7a (patch) | |
| tree | 01d02d3ba396cf68a1c6cdd6dcd64e946a48a309 /src/libstd/thread | |
| parent | f4d03da825160c9e1d3550dd9769ef4b96ef8e89 (diff) | |
| download | rust-d5a27594a3abeee9a8c81cc016dfb3a5b8b51d7a.tar.gz rust-d5a27594a3abeee9a8c81cc016dfb3a5b8b51d7a.zip | |
Add examples for `std::thread::Thread::name`.
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 c8783a60c41..5f74ec639f1 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -478,6 +478,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()) } ) |
