Skip to main content

Builder

Struct Builder 

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

Thread factory mirroring std::thread::Builder, with app binding (ADR-314).

Same knobs as the std builder — Builder::name and Builder::stack_size — plus the host bind/unbind around the closure. Use this when an app needs a named long-lived thread or a smaller stack (for example 512 KiB on a Pi Zero 2 W); use spawn when the defaults are enough.

§Examples

use node_app_sdk_rust::thread::Builder;

let handle = Builder::new()
    .name("worker".into())
    .stack_size(512 * 1024)
    .spawn(|| 6 * 7)
    .unwrap();
assert_eq!(handle.join().unwrap(), 42);

Implementations§

Source§

impl Builder

Source

pub fn new() -> Self

Same defaults as std::thread::Builder::new.

Source

pub fn name(self, name: String) -> Self

Sets the name of the thread for debugging and panic messages.

Source

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

Sets the size of the stack (in bytes) for the new thread.

Source

pub fn spawn<F, T>(self, f: F) -> Result<JoinHandle<T>>
where F: FnOnce() -> T + Send + 'static, T: Send + 'static,

Spawns an OS thread that is bound to this app (ADR-314).

Everything std::thread::Builder::spawn does, plus the binding: the host charges the new thread’s CPU and the memory it allocates to this app from the moment it starts until it exits. The binding is released when the closure returns — including when it panics, and including when the OS refuses to start the thread (then there is nothing to release).

A host that predates ADR-314 exports no hooks: the closure still runs and nothing else happens.

§Errors

The OS could not create a thread; the closure never runs.

Trait Implementations§

Source§

impl Default for Builder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.