Rollup merge of #38491 - GuillaumeGomez:builder_docs, r=frewsxcv
Builder docs r? @frewsxcv
This commit is contained in:
@@ -216,6 +216,20 @@ pub use self::local::{LocalKey, LocalKeyState};
|
|||||||
|
|
||||||
/// Thread configuration. Provides detailed control over the properties
|
/// Thread configuration. Provides detailed control over the properties
|
||||||
/// and behavior of new threads.
|
/// and behavior of new threads.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use std::thread;
|
||||||
|
///
|
||||||
|
/// let builder = thread::Builder::new();
|
||||||
|
///
|
||||||
|
/// let handler = builder.spawn(|| {
|
||||||
|
/// // thread code
|
||||||
|
/// }).unwrap();
|
||||||
|
///
|
||||||
|
/// handler.join().unwrap();
|
||||||
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Builder {
|
pub struct Builder {
|
||||||
@@ -228,6 +242,22 @@ pub struct Builder {
|
|||||||
impl Builder {
|
impl Builder {
|
||||||
/// Generates the base configuration for spawning a thread, from which
|
/// Generates the base configuration for spawning a thread, from which
|
||||||
/// configuration methods can be chained.
|
/// configuration methods can be chained.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use std::thread;
|
||||||
|
///
|
||||||
|
/// let builder = thread::Builder::new()
|
||||||
|
/// .name("foo".into())
|
||||||
|
/// .stack_size(10);
|
||||||
|
///
|
||||||
|
/// let handler = builder.spawn(|| {
|
||||||
|
/// // thread code
|
||||||
|
/// }).unwrap();
|
||||||
|
///
|
||||||
|
/// handler.join().unwrap();
|
||||||
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn new() -> Builder {
|
pub fn new() -> Builder {
|
||||||
Builder {
|
Builder {
|
||||||
@@ -241,7 +271,7 @@ impl Builder {
|
|||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```
|
||||||
/// use std::thread;
|
/// use std::thread;
|
||||||
///
|
///
|
||||||
/// let builder = thread::Builder::new()
|
/// let builder = thread::Builder::new()
|
||||||
@@ -260,6 +290,14 @@ impl Builder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Sets the size of the stack for the new thread.
|
/// Sets the size of the stack for the new thread.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use std::thread;
|
||||||
|
///
|
||||||
|
/// let builder = thread::Builder::new().stack_size(10);
|
||||||
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn stack_size(mut self, size: usize) -> Builder {
|
pub fn stack_size(mut self, size: usize) -> Builder {
|
||||||
self.stack_size = Some(size);
|
self.stack_size = Some(size);
|
||||||
@@ -275,9 +313,26 @@ impl Builder {
|
|||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
///
|
///
|
||||||
/// Unlike the `spawn` free function, this method yields an
|
/// Unlike the [`spawn`] free function, this method yields an
|
||||||
/// `io::Result` to capture any failure to create the thread at
|
/// [`io::Result`] to capture any failure to create the thread at
|
||||||
/// the OS level.
|
/// the OS level.
|
||||||
|
///
|
||||||
|
/// [`spawn`]: ../../std/thread/fn.spawn.html
|
||||||
|
/// [`io::Result`]: ../../std/io/type.Result.html
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use std::thread;
|
||||||
|
///
|
||||||
|
/// let builder = thread::Builder::new();
|
||||||
|
///
|
||||||
|
/// let handler = builder.spawn(|| {
|
||||||
|
/// // thread code
|
||||||
|
/// }).unwrap();
|
||||||
|
///
|
||||||
|
/// handler.join().unwrap();
|
||||||
|
/// ```
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub fn spawn<F, T>(self, f: F) -> io::Result<JoinHandle<T>> where
|
pub fn spawn<F, T>(self, f: F) -> io::Result<JoinHandle<T>> where
|
||||||
F: FnOnce() -> T, F: Send + 'static, T: Send + 'static
|
F: FnOnce() -> T, F: Send + 'static, T: Send + 'static
|
||||||
|
|||||||
Reference in New Issue
Block a user