Struct wasm_thread::Builder

source ·
pub struct Builder { /* private fields */ }
Expand description

Thread factory, which can be used in order to configure the properties of a new thread.

Implementations§

source§

impl Builder

source

pub fn spawn_scoped<'scope, 'env, F, T>( self, scope: &'scope Scope<'scope, 'env>, f: F ) -> Result<ScopedJoinHandle<'scope, T>>
where F: FnOnce() -> T + Send + 'scope, T: Send + 'scope,

Spawns a new scoped thread using the settings set through this Builder.

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

source§

impl Builder

source

pub fn new() -> Builder

Creates a builder inheriting global configuration options set by Self::set_default.

source

pub fn empty() -> Builder

Creates a builder without inheriting global options set by Self::set_default.

source

pub fn set_default(self)

Sets current values as global default for all new builders created with Builder::new or Builder::default.

source

pub fn prefix(self, prefix: String) -> Builder

Sets the prefix of the thread.

source

pub fn worker_script_url(self, worker_script_url: String) -> Builder

source

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

Sets the name of the thread.

If not set, the default name is autogenerated.

source

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

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

§Warning

This is currently not supported by wasm, but provided for API consistency with std::thread.

source

pub fn wasm_bindgen_shim_url(self, url: String) -> Builder

Sets the URL of wasm_bindgen generated shim script.

source

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

Spawns a new thread by taking ownership of the Builder, and returns an std::io::Result to its JoinHandle.

source

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

Spawns a new thread without any lifetime restrictions by taking ownership of the Builder, and returns an std::io::Result to its JoinHandle.

§Safety

The caller has to ensure that no references in the supplied thread closure or its return type can outlive the spawned thread’s lifetime. This can be guaranteed in two ways:

  • ensure that join is called before any referenced data is dropped
  • use only types with 'static lifetime bounds, i.e., those with no or only 'static references (both Builder::spawn and spawn enforce this property statically)

Trait Implementations§

source§

impl Clone for Builder

source§

fn clone(&self) -> Builder

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Builder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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.