pub struct State<T> { /* private fields */ }Expand description
This API violates core assumption of turbo-tasks, is believed to be unsound, and there’s no plan fix it. You should prefer to use collectibles instead of state where at all possible. This API may be removed in the future.
An internally-mutable type, similar to RefCell or [Mutex] that can
be stored inside a VcValueType.
State should only be used with OperationVc and types that implement
OperationValue.
Setting values inside a State bypasses the normal argument and return value tracking
that’s tracks child function calls and re-runs tasks until their values settled. That system is
needed for strong consistency. OperationVc ensures that function calls are reconnected
with the parent/child call graph.
When reading a State with State::get, the state itself (though not any values inside of
it) is marked as a dependency of the current task.
Implementations§
Source§impl<T> State<T>
impl<T> State<T>
pub fn new(value: T) -> Selfwhere
T: OperationValue,
Sourcepub fn get(&self) -> StateRef<'_, T>
pub fn get(&self) -> StateRef<'_, T>
Gets the current value of the state. The current task will be registered as dependency of the state and will be invalidated when the state changes.
Sourcepub fn get_untracked(&self) -> StateRef<'_, T>
pub fn get_untracked(&self) -> StateRef<'_, T>
Gets the current value of the state. Untracked.
Sourcepub fn set_unconditionally(&self, value: T)
pub fn set_unconditionally(&self, value: T)
Sets the current state without comparing it with the old value. This should only be used if one is sure that the value has changed.
Sourcepub fn update_conditionally(&self, update: impl FnOnce(&mut T) -> bool)
pub fn update_conditionally(&self, update: impl FnOnce(&mut T) -> bool)
Updates the current state with the update function. The update
function need to return true when the value was modified. Exposing
the current value from the update function is not allowed and will
result in incorrect cache invalidation.
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for State<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for State<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<T: TraceRawVcs> TraceRawVcs for State<T>
impl<T: TraceRawVcs> TraceRawVcs for State<T>
fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext)
fn get_raw_vcs(&self) -> Vec<RawVc>
impl<T> Eq for State<T>
impl<T: NonLocalValue> NonLocalValue for State<T>
impl<T: OperationValue> OperationValue for State<T>
Auto Trait Implementations§
impl<T> !Freeze for State<T>
impl<T> !RefUnwindSafe for State<T>
impl<T> Send for State<T>where
T: Send,
impl<T> Sync for State<T>where
T: Send,
impl<T> Unpin for State<T>where
T: Unpin,
impl<T> !UnwindSafe for State<T>
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> DynPartialEq for T
impl<T> DynPartialEq for T
fn dyn_partial_eq(&self, other: &(dyn Any + 'static)) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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