pub struct ThreadLocal<T: Send> { /* private fields */ }
Expand description

Thread-local variable wrapper

See the module-level documentation for more.

Implementations§

Creates a new empty ThreadLocal.

Creates a new ThreadLocal with an initial capacity. If less than the capacity threads access the thread local it will never reallocate. The capacity may be rounded up to the nearest power of two.

Returns the element for the current thread, if it exists.

Returns the element for the current thread, or creates it if it doesn’t exist.

Returns the element for the current thread, or creates it if it doesn’t exist. If create fails, that error is returned and no element is added.

Returns an iterator over the local values of all threads in unspecified order.

This call can be done safely, as T is required to implement Sync.

Returns a mutable iterator over the local values of all threads in unspecified order.

Since this call borrows the ThreadLocal mutably, this operation can be done safely—the mutable borrow statically guarantees no other threads are currently accessing their associated values.

Removes all thread-specific values from the ThreadLocal, effectively reseting it to its original state.

Since this call borrows the ThreadLocal mutably, this operation can be done safely—the mutable borrow statically guarantees no other threads are currently accessing their associated values.

Returns the element for the current thread, or creates a default one if it doesn’t exist.

Trait Implementations§

Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Executes the destructor for this type. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. 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.