Struct thread_isolated::ThreadIsolated [] [src]

pub struct ThreadIsolated<T, ThreadKind> {
    // some fields omitted
}

A reference-counted RefCell<T> exposed in two different ways, depending on the ThreadKind phantom type.

Methods

impl<T> ThreadIsolated<T, OwningThread>

unsafe fn new<R: IsolationRunner>(item: T, runner: R) -> ThreadIsolated<T, OwningThread>

Create a new thread-isolated value. The given runner's implementation must run any closures it is given on the thread currently calling new.

Function is unsafe because if the runner does not run closures on the current thread, memory unsafety will occur.

fn borrow(&self) -> Ref<T>

Immutably borrows the wrapped value.

The borrow lasts until the returned Ref exits scope. Multiple immutable borrows can be taken out at the same time.

Panics

Panics if the value is currently mutably borrowed.

fn borrow_mut(&self) -> RefMut<T>

Mutably borrows the wrapped value.

The borrow lasts until the returned RefMut exits scope. The value cannot be borrowed while this borrow is active.

Panics

Panics if the value is currently borrowed.

fn clone_for_non_owning_thread(&self) -> ThreadIsolated<T, NonOwningThread>

Clones the contained RefCell into a ThreadIsolated<T, NonOwningThread> that can be sent and shared with other threads.

fn downgrade_for_non_owning_thread(&self) -> ThreadIsolatedWeak<T>

Downgreads the ThreadIsolated<T, OwningThread> to a ThreadIsolatedWeak<T>.

impl<T> ThreadIsolated<T, NonOwningThread>

unsafe fn as_owning_thread(self) -> ThreadIsolated<T, OwningThread>

Convert a ThreadIsolated<T, NonOwningThread> into a ThreadIsolated<T, OwningThread>.

Function is unsafe because the returned ThreadIsolated is only safe to access from the thread that created the original ThreadIsolated<T, OwningThread> from which this instance was cloned.

fn with<U, F>(&self, f: F) -> U where F: FnOnce(&RefCell<T>) -> U + Send, U: Send

Run a closure that has access to the contained RefCell on the original owning thread.

This function blocks until the original thread has run f. This means (among other things) that with will deadlock if you call it from the thread that owns the underlying value.

Trait Implementations

impl<T> Clone for ThreadIsolated<T, NonOwningThread>

fn clone(&self) -> ThreadIsolated<T, NonOwningThread>

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

impl<T> Send for ThreadIsolated<T, NonOwningThread>

impl<T> Sync for ThreadIsolated<T, NonOwningThread>