pub struct StaticInstancePerThread<T>where
T: Object,{ /* private fields */ }Expand description
This is the real type of variables wrapped in the linked::thread_local_rc! macro.
See macro documentation for more details.
Instances of this type are created by the linked::thread_local_rc! macro,
never directly by user code, which can call .with() or .to_rc()
to work with or obtain a linked instance of T.
Implementations§
Source§impl<T> StaticInstancePerThread<T>where
T: Object,
impl<T> StaticInstancePerThread<T>where
T: Object,
Sourcepub fn with<F, R>(&self, f: F) -> R
pub fn with<F, R>(&self, f: F) -> R
Executes a closure with the current thread’s linked instance from the object family referenced by the static variable.
§Performance
For repeated access to the current thread’s linked instance, prefer reusing an Rc<T>
obtained from .to_rc().
If your code is not in a situation where it can reuse an existing Rc<T>, this method is
the optimal way to access the current thread’s linked instance of T.
Sourcepub fn to_rc(&self) -> Rc<T>
pub fn to_rc(&self) -> Rc<T>
Gets an Rc<T> to the current thread’s linked instance from
the object family referenced by the static variable.
The instance behind this Rc is the same one accessed by all other calls through the static
variable on this thread. Note that it is still possible to create multiple instances on a
single thread, e.g. by cloning the T within. The “one instance per thread” logic only
applies when the instances are accessed through the static variable.
§Performance
This function merely clones an Rc, which is relatively fast but still more work than
doing nothing. The most efficient way to access the current thread’s linked instance is
to reuse the Rc<T> returned from this method.
If you are not in a situation where you can reuse the Rc<T> and a shared reference is
satisfactory, prefer calling .with() instead, which does not create an
Rc and thereby saves a few nanoseconds.