pub struct Builder { /* private fields */ }Expand description
Fluent thread-spawn configuration. Construct via Thread::builder.
Default-constructable so chains like
Builder::new().name(c"foo").spawn(...) also work. Required-field
validation happens at spawn time; missing name
uses an empty default which most RTOSes accept.
Implementations§
Source§impl Builder
impl Builder
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a new builder with default settings: no name, normal priority, 4 KB stack.
Sourcepub fn name(self, name: &'static CStr) -> Self
pub fn name(self, name: &'static CStr) -> Self
Set the thread name. Use a c"..." literal (Rust 1.77+) to
guarantee null termination at compile time.
Sourcepub fn stack_size(self, stack_size: usize) -> Self
pub fn stack_size(self, stack_size: usize) -> Self
Set the stack size in bytes.
Sourcepub fn spawn<F>(self, f: F) -> Result<JoinHandle<()>>
pub fn spawn<F>(self, f: F) -> Result<JoinHandle<()>>
Spawn a thread with a FnOnce(StopToken) closure.
Cooperative cancellation is built in: when the returned
JoinHandle goes out of scope, Drop calls
JoinHandle::request_stop before waiting for the worker so a
while !tok.is_stopped() loop exits cleanly. Use
JoinHandle::detach to opt out of the join-on-drop.
The closure is heap-allocated; requires the alloc feature and
a registered #[global_allocator].
§Errors
Returns Error::NoMemory on allocation failure or another
error if the RTOS rejects the descriptor.
Sourcepub fn spawn_cooperative(self, entry: fn(StopToken)) -> Result<JoinHandle<()>>
pub fn spawn_cooperative(self, entry: fn(StopToken)) -> Result<JoinHandle<()>>
Spawn a thread with a stateless fn(StopToken) entry.
Heap-allocator-free variant of Builder::spawn. The entry
pointer is round-tripped through *mut c_void (guarded by a
compile-time size check). No captures supported.
§Errors
See Builder::spawn.
Sourcepub fn spawn_simple(self, entry: fn()) -> Result<JoinHandle<()>>
pub fn spawn_simple(self, entry: fn()) -> Result<JoinHandle<()>>
Spawn a thread with a stateless fn() entry (no StopToken).
Use when the worker is a self-terminating one-shot — it returns
from its entry function on its own. Drop on the returned
JoinHandle still requests stop (no-op if the worker doesn’t
observe), then waits for the entry function to return.
§Errors
See Builder::spawn.