Struct TaskRc

Source
pub struct TaskRc<A> { /* private fields */ }
👎Deprecated since 0.1.4: replaced with BiLock in many cases, otherwise slated for removal due to confusion
Expand description

A reference to a piece of data that’s accessible only within a specific Task.

This data is Send even when A is not Sync, because the data stored within is accessed in a single-threaded way. The thread accessing it may change over time, if the task migrates, so A must be Send.

Implementations§

Source§

impl<A> TaskRc<A>

Source

pub fn new(a: A) -> TaskRc<A>

👎Deprecated since 0.1.4: replaced with BiLock in many cases, otherwise slated for removal due to confusion

Inserts a new piece of task-local data into this task, returning a reference to it.

Ownership of the data will be transferred to the task, and the data will be destroyed when the task itself is destroyed. The returned value can be passed to the with method to get a reference back to the original data.

Note that the returned handle is cloneable and copyable and can be sent to other futures which will be associated with the same task. All futures will then have access to this data when passed the reference back.

§Panics

This function will panic if a task is not currently running.

Source

pub fn with<F, R>(&self, f: F) -> R
where F: FnOnce(&A) -> R,

👎Deprecated since 0.1.4: replaced with BiLock in many cases, otherwise slated for removal due to confusion

Operate with a reference to the underlying data.

This method should be passed a handle previously returned by Task::insert. That handle, when passed back into this method, will retrieve a reference to the original data.

§Panics

This method will panic if a task is not currently running or if self does not belong to the task that is currently running. That is, if another task generated the data handle passed in, this method will panic.

Trait Implementations§

Source§

impl<A> Clone for TaskRc<A>

Source§

fn clone(&self) -> TaskRc<A>

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<A> Debug for TaskRc<A>
where A: Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<A> Send for TaskRc<A>
where A: Send,

Source§

impl<A> Sync for TaskRc<A>
where A: Sync,

Auto Trait Implementations§

§

impl<A> Freeze for TaskRc<A>

§

impl<A> !RefUnwindSafe for TaskRc<A>

§

impl<A> Unpin for TaskRc<A>

§

impl<A> !UnwindSafe for TaskRc<A>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

Source§

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

Source§

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.