Skip to main content

Builder

Struct Builder 

Source
pub struct Builder { /* private fields */ }
Expand description

A builder for configuring and spawning threads.

§Examples

let t = Builder::new()
    .name("worker")
    .priority(16)
    .stack_size(0x4000)
    .spawn(|| { /* ... */ });

Implementations§

Source§

impl Builder

Source

pub const DEFAULT_STACK_SIZE: usize = 0x2000

Default stack size used when none is specified (8 KiB).

Source

pub fn new() -> Self

Creates a builder with default settings: 8 KiB dynamic stack, priority 16, started immediately.

Source

pub fn name(self, name: &str) -> Self

Sets the thread name, truncated to 31 bytes.

Source

pub fn halted(self) -> Self

Creates the thread in a halted state; call Thread::start to begin execution.

Source

pub fn stack(self, stack: &'static mut [u8]) -> Self

Uses a caller-provided static buffer as the thread stack instead of allocating one.

Source

pub fn stack_size(self, size: usize) -> Self

Sets the size in bytes for the dynamically allocated stack.

Source

pub fn priority(self, priority: i32) -> Self

Sets the thread scheduling priority.

Source

pub fn spawn<F: FnOnce() + Send + 'static>(self, f: F) -> Thread

Consumes the builder and spawns a thread running f.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.