pub struct LocalKey<T> { /* private fields */ }
Expand description

A JavaScript thread-local container that owns its contents, similar to std::thread::LocalKey but tied to a JavaScript thread rather than a system thread.

Initialization and Destruction

Initialization is dynamically performed on the first call to one of the init methods of LocalKey, and values that implement Drop get destructed when the JavaScript thread exits, i.e. when a worker thread terminates or the main thread terminates on process exit.

Implementations

Creates a new local value. This method is const, so it can be assigned to static variables.

Gets the current value of the cell. Returns None if the cell has not yet been initialized.

Gets the current value of the cell, initializing it with the result of calling f if it has not yet been initialized.

Gets the current value of the cell, initializing it with the result of calling f if it has not yet been initialized. Returns Err if the callback triggers a JavaScript exception.

Panics

During the execution of f, calling any methods on this LocalKey that attempt to initialize it will panic.

Gets the current value of the cell, initializing it with the default value if it has not yet been initialized.

Trait Implementations

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.