Struct State

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

Source

pub fn new(value: T) -> Self
where T: OperationValue,

Source

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.

Source

pub fn get_untracked(&self) -> StateRef<'_, T>

Gets the current value of the state. Untracked.

Source

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.

Source

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.

Source§

impl<T: PartialEq> State<T>

Source

pub fn set(&self, value: T)

Update the current state when the value is different from the current value. T must implement PartialEq for this to work.

Trait Implementations§

Source§

impl<T: Debug> Debug for State<T>

Source§

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

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

impl<T: Default + OperationValue> Default for State<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

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

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T> PartialEq for State<T>

Source§

fn eq(&self, _other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Serialize for State<T>
where T: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: TraceRawVcs> TraceRawVcs for State<T>

Source§

fn trace_raw_vcs(&self, trace_context: &mut TraceRawVcsContext)

Source§

fn get_raw_vcs(&self) -> Vec<RawVc>

Source§

impl<T> Eq for State<T>

Source§

impl<T: NonLocalValue> NonLocalValue for State<T>

Source§

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§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Any for T
where T: Any,

§

fn get_type_id(&self) -> TypeId

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
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,