Skip to main content

KeyedReadRef

Struct KeyedReadRef 

Source
pub struct KeyedReadRef<T>
where T: VcValueType, <<T as VcValueType>::Read as VcRead<T>>::Target: KeyedEq,
{ /* private fields */ }
Expand description

The result of Vc::keyed_reader: a read of a keyed cell (a cell = "keyed" map or set) that only allows synchronous keyed access via KeyedReadRef::get and KeyedReadRef::contains_key.

This is an efficient alternative to many Vc::get / Vc::contains_key reads of the same cell within a single task: the cell is read (and the dependency registered) only once, and the accessed keys don’t need an await or any locking of the backend.

While it is alive, the reading task depends on the whole cell, so it is invalidated by any change. The hashes of the accessed keys are recorded. When it is dropped within the task execution that read it, that dependency is replaced (in a single batch operation) with dependencies on only the accessed keys, so the task is only invalidated when one of the accessed keys changes, like with Vc::get.

It must be dropped within the task execution that called keyed_reader (it may be dropped in local tasks of that execution), and the same applies to the future returned by keyed_reader. When either is still alive at the end of that task execution (e.g. forgotten, or moved to another thread or task), that is a bug in the task function: completing the execution panics, which aborts the process.

Note: Like with Vc::contains_key, a contains_key access is also invalidated when the value of the key changes, not only when its presence changes.

Implementations§

Source§

impl<T> KeyedReadRef<T>
where T: VcValueType, <<T as VcValueType>::Read as VcRead<T>>::Target: KeyedEq,

Source

pub fn get<Q>( &self, key: &Q, ) -> Option<&<<<T as VcValueType>::Read as VcRead<T>>::Target as KeyedAccess<Q>>::Value>
where Q: Hash + ?Sized, <<T as VcValueType>::Read as VcRead<T>>::Target: KeyedAccess<Q>,

Selects a keyed value. The task will only depend on the accessed keys.

Source

pub fn contains_key<Q>(&self, key: &Q) -> bool
where Q: Hash + ?Sized, <<T as VcValueType>::Read as VcRead<T>>::Target: KeyedAccess<Q>,

Checks if the value contains the given key. The task will only depend on the accessed keys.

Note: This is also invalidated when the value of the key changes, not only when the presence of the key changes.

Trait Implementations§

Source§

impl<T> Debug for KeyedReadRef<T>
where T: VcValueType, <<T as VcValueType>::Read as VcRead<T>>::Target: KeyedEq,

Source§

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

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

impl<T> Drop for KeyedReadRef<T>
where T: VcValueType, <<T as VcValueType>::Read as VcRead<T>>::Target: KeyedEq,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for KeyedReadRef<T>

§

impl<T> !RefUnwindSafe for KeyedReadRef<T>

§

impl<T> Forget for KeyedReadRef<T>

§

impl<T> Move for KeyedReadRef<T>

§

impl<T> Send for KeyedReadRef<T>
where ReadRef<T>: Send,

§

impl<T> Sync for KeyedReadRef<T>
where ReadRef<T>: Sync,

§

impl<T> Unpin for KeyedReadRef<T>
where ReadRef<T>: Unpin,

§

impl<T> UnsafeUnpin for KeyedReadRef<T>
where ReadRef<T>: UnsafeUnpin,

§

impl<T> UnwindSafe for KeyedReadRef<T>
where ReadRef<T>: UnwindSafe,

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> MaybeTypeTag for T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more