[][src]Struct ctx_thread::ContextThreadBuilder

pub struct ContextThreadBuilder<'scope, 'env> { /* fields omitted */ }

Configures the properties of a new thread.

The two configurable properties are:

The spawn method will take ownership of the builder and return an io::Result of the thread handle with the given configuration.

The Context::spawn method uses a builder with default configuration and unwraps its return value. You may want to use this builder when you want to recover from a failure to launch a thread.

Examples

use ctx_thread::scope;

scope(|ctx| {
    ctx.builder()
        .spawn(|_| println!("Running a child thread"))
        .unwrap();
}).unwrap();

Implementations

impl<'scope, 'env> ContextThreadBuilder<'scope, 'env>[src]

pub fn name(self, name: String) -> ContextThreadBuilder<'scope, 'env>[src]

Sets the name for the new thread.

The name must not contain null bytes (\0).

For more information about named threads, see [here][naming-threads].

pub fn stack_size(self, size: usize) -> ContextThreadBuilder<'scope, 'env>[src]

Sets the size of the stack for the new thread.

The stack size is measured in bytes.

For more information about the stack size for threads, see [here][stack-size].

pub fn spawn<F, T>(self, f: F) -> Result<ContextJoinHandle<'scope, T>> where
    F: FnOnce(&Context<'env>) -> T,
    F: Send + 'env,
    T: Send + 'env, 
[src]

Spawns a scoped thread with this configuration, providing a derived context.

The scoped thread is passed a reference to this scope as an argument, which can be used for spawning nested threads.

The returned handle can be used to manually join the thread before the scope exits.

Errors

Unlike the [Scope::spawn] method, this method yields an io::Result to capture any failure to create the thread at the OS level.

Panics

Panics if a thread name was set and it contained null bytes.

Examples

use ctx_thread::scope;

scope(|ctx| {
    let handle = ctx.builder()
        .spawn(|_| {
            println!("A child thread is running");
            42
        })
        .unwrap();

    // Join the thread and retrieve its result.
    let res = handle.join().unwrap();
    assert_eq!(res, 42);
}).unwrap();

Trait Implementations

impl<'scope, 'env> Debug for ContextThreadBuilder<'scope, 'env>[src]

Auto Trait Implementations

impl<'scope, 'env> !RefUnwindSafe for ContextThreadBuilder<'scope, 'env>

impl<'scope, 'env> Send for ContextThreadBuilder<'scope, 'env>

impl<'scope, 'env> Sync for ContextThreadBuilder<'scope, 'env>

impl<'scope, 'env> Unpin for ContextThreadBuilder<'scope, 'env> where
    'env: 'scope, 

impl<'scope, 'env> !UnwindSafe for ContextThreadBuilder<'scope, 'env>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.