#[value]Expand description
Implements VcValueType for the given struct or enum. These value types can be used
inside of a “value cell” as Vc<...>.
A Vc represents a (potentially lazy) memoized computation. Each Vc’s value is placed
into a cell associated with the current TaskId. That Vc object can be awaited to get
a read-only reference to the value contained in the cell.
This macro accepts multiple comma-separated arguments. For example:
#[turbo_tasks::value(transparent, shared)]
struct Foo(Vec<u32>);§cell = "..."
Controls when a cell is invalidated upon recomputation of a task. Internally, this is performed
by setting the VcValueType::CellMode associated type.
"new": Always overrides the value in the cell, invalidating all dependent tasks."compare"(default): Compares with the existing value in the cell, before overriding it. Requires the value to implementEq.
Avoiding unnecessary invalidation is important to reduce downstream recomputation of tasks that depend on this cell’s value.
Use "new" only if a correct implementation of Eq is not possible, would be expensive (e.g.
would require comparing a large collection), or if you’re implementing a low-level primitive
that intentionally forces recomputation.
§eq = "..."
By default, we #[derive(PartialEq, Eq)]. Eq is required by cell = "compare". This
argument allows overriding that default implementation behavior.
§serialization = "..."
Affects serialization via serde::Serialize and serde::Deserialize. Serialization is
required for filesystem cache of tasks.
"auto"(default): Derives the serialization traits and enables serialization."custom": Prevents deriving the serialization traits, but still enables serialization (you must manually implementserde::Serializeandserde::Deserialize)."none": Disables serialization and prevents deriving the traits.
§shared
Makes the cell() method public so everyone can use it.
§transparent
This attribute is only valid on single-element unit structs. When this value is set:
- The struct will use
#[repr(transparent)]. - Read operations (
vc.await?) return aReadRefcontaining the inner type, rather than the outer struct. Internally, this is accomplished usingVcTransparentReadfor theVcValueType::Readassociated type. - Construction of the type must be performed using
Vc::cell(inner), rather than using the.cell()method on the outer type (outer.cell()). - The
ValueDebugimplementation will defer to the inner type.
This is commonly used to create VcValueType wrappers for foreign or generic types, such as
Vec or Option.
§local
Skip the implementation of NonLocalValue for this type.
If not specified, we apply the #[derive(NonLocalValue)] macro, which
asserts that this struct has no fields containing Vc by implementing the NonLocalValue
marker trait. Compile-time assertions are generated on every field, checking that they are also
NonLocalValues.