Skip to content

Commit 2cfd91d

Browse files
authored
Auto merge of #34465 - frewsxcv:builder-name-example, r=GuillaumeGomez
Add doc example for `std::thread::Builder::name`. None
2 parents 91c0d04 + fd388d4 commit 2cfd91d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/libstd/thread/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,21 @@ impl Builder {
220220

221221
/// Names the thread-to-be. Currently the name is used for identification
222222
/// only in panic messages.
223+
///
224+
/// # Examples
225+
///
226+
/// ```rust
227+
/// use std::thread;
228+
///
229+
/// let builder = thread::Builder::new()
230+
/// .name("foo".into());
231+
///
232+
/// let handler = builder.spawn(|| {
233+
/// assert_eq!(thread::current().name(), Some("foo"))
234+
/// }).unwrap();
235+
///
236+
/// handler.join().unwrap();
237+
/// ```
223238
#[stable(feature = "rust1", since = "1.0.0")]
224239
pub fn name(mut self, name: String) -> Builder {
225240
self.name = Some(name);

0 commit comments

Comments
 (0)