about summary refs log tree commit diff
path: root/src/libstd/thread
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2016-06-21 23:54:28 +0200
committerGitHub <noreply@github.com>2016-06-21 23:54:28 +0200
commit592c314baf81893485e765091809f23103242058 (patch)
tree4a7c03c2a77630a505fccdf1f488f33d2fc94b9a /src/libstd/thread
parent0b566f6bec1dd171525a82a8a25154c354dd1fdf (diff)
parentd5a27594a3abeee9a8c81cc016dfb3a5b8b51d7a (diff)
downloadrust-592c314baf81893485e765091809f23103242058.tar.gz
rust-592c314baf81893485e765091809f23103242058.zip
Rollup merge of #34371 - frewsxcv:thread-name, r=steveklabnik
Add examples for `std::thread::Thread::name`.

None
Diffstat (limited to 'src/libstd/thread')
-rw-r--r--src/libstd/thread/mod.rs31
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()) } )