@@ -216,6 +216,20 @@ pub use self::local::{LocalKey, LocalKeyState};
216216
217217/// Thread configuration. Provides detailed control over the properties
218218/// and behavior of new threads.
219+ ///
220+ /// # Examples
221+ ///
222+ /// ```
223+ /// use std::thread;
224+ ///
225+ /// let builder = thread::Builder::new();
226+ ///
227+ /// let handler = builder.spawn(|| {
228+ /// // thread code
229+ /// }).unwrap();
230+ ///
231+ /// handler.join().unwrap();
232+ /// ```
219233#[ stable( feature = "rust1" , since = "1.0.0" ) ]
220234#[ derive( Debug ) ]
221235pub struct Builder {
@@ -228,6 +242,22 @@ pub struct Builder {
228242impl Builder {
229243 /// Generates the base configuration for spawning a thread, from which
230244 /// configuration methods can be chained.
245+ ///
246+ /// # Examples
247+ ///
248+ /// ```
249+ /// use std::thread;
250+ ///
251+ /// let builder = thread::Builder::new()
252+ /// .name("foo".into())
253+ /// .stack_size(10);
254+ ///
255+ /// let handler = builder.spawn(|| {
256+ /// // thread code
257+ /// }).unwrap();
258+ ///
259+ /// handler.join().unwrap();
260+ /// ```
231261 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
232262 pub fn new ( ) -> Builder {
233263 Builder {
@@ -241,7 +271,7 @@ impl Builder {
241271 ///
242272 /// # Examples
243273 ///
244- /// ```rust
274+ /// ```
245275 /// use std::thread;
246276 ///
247277 /// let builder = thread::Builder::new()
@@ -260,6 +290,14 @@ impl Builder {
260290 }
261291
262292 /// Sets the size of the stack for the new thread.
293+ ///
294+ /// # Examples
295+ ///
296+ /// ```
297+ /// use std::thread;
298+ ///
299+ /// let builder = thread::Builder::new().stack_size(10);
300+ /// ```
263301 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
264302 pub fn stack_size ( mut self , size : usize ) -> Builder {
265303 self . stack_size = Some ( size) ;
@@ -275,9 +313,26 @@ impl Builder {
275313 ///
276314 /// # Errors
277315 ///
278- /// Unlike the `spawn` free function, this method yields an
279- /// `io::Result` to capture any failure to create the thread at
316+ /// Unlike the [ `spawn`] free function, this method yields an
317+ /// [ `io::Result`] to capture any failure to create the thread at
280318 /// the OS level.
319+ ///
320+ /// [`spawn`]: ../../std/thread/fn.spawn.html
321+ /// [`io::Result`]: ../../std/io/type.Result.html
322+ ///
323+ /// # Examples
324+ ///
325+ /// ```
326+ /// use std::thread;
327+ ///
328+ /// let builder = thread::Builder::new();
329+ ///
330+ /// let handler = builder.spawn(|| {
331+ /// // thread code
332+ /// }).unwrap();
333+ ///
334+ /// handler.join().unwrap();
335+ /// ```
281336 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
282337 pub fn spawn < F , T > ( self , f : F ) -> io:: Result < JoinHandle < T > > where
283338 F : FnOnce ( ) -> T , F : Send + ' static , T : Send + ' static
0 commit comments