Skip to main content

TaskInput

Trait TaskInput 

Source
pub trait TaskInput:
    Send
    + Sync
    + Clone
    + Debug
    + PartialEq
    + Eq
    + Hash
    + TraceRawVcs
    + Encode
    + Decode<()> {
    // Required method
    fn is_transient(&self) -> bool;

    // Provided methods
    fn resolve_input(&self) -> impl Future<Output = Result<Self>> + Send + '_ { ... }
    fn is_resolved(&self) -> bool { ... }
}
Expand description

Trait to implement in order for a type to be accepted as a #[turbo_tasks::function] argument.

§Serialization

For persistent caching of a task, arguments must be serializable. All TaskInputs must implement the bincode Encode and Decode traits.

Transient task inputs are required to implement Encode and Decode, but are allowed to panic at runtime. This requirement could be lifted in the future.

Bincode encoding must be deterministic and compatible with Eq comparisons. If two TaskInputs compare equal they must also encode to the same bytes.

§Hash and Eq

Arguments are used as part of keys in a HashMap, so they must implement of PartialEq, Eq, and Hash traits.

§Vc<T>

A Vc is a pointer to a cell. It implements TaskInput and serves as a “pass by reference” argument:

  • Memoization: Vc is keyed by pointer for memoization purposes. Identical values in different cells are treated as distinct.
  • Singleton Pattern: To ensure memoization efficiency, the singleton pattern can be employed to guarantee that identical values yield the same Vc. For more info see Singleton Pattern Guide.

§Deriving TaskInput

Structs or enums can be made into task inputs by deriving TaskInput:

#[derive(TaskInput)]
struct MyStruct {
    // Fields go here...
}

Derived TaskInput types passed by value. When called, arguments are moved into a Box, and then cloned before being passed into the function. If the task is invalidated, the TaskInput is cloned again to allow the function to be re-executed. It’s recommended to ensure that these types are cheap to clone.

Reference-counted types like Arc are cheap to clone, but each reference contained in a TaskInput will be serialized independently in the persistent cache, and may consume extra disk space. If an Arc points to a large type, consider wrapping that type in Vc, so that only one copy of the value will be serialized.

Required Methods§

Source

fn is_transient(&self) -> bool

This should return true if this object contains a Vc (or any subtype of Vc) pointing to a cell owned by a transient task.

Any function called with a transient TaskInput will be transient. Any Vc constructed in a transient task or in a top-level run_once closure will be transient.

Internally, a Vc can be determined to be transient by comparing the owning task’s id with the TRANSIENT_TASK_BIT mask.

Provided Methods§

Source

fn resolve_input(&self) -> impl Future<Output = Result<Self>> + Send + '_

This method should resolve any Vcs nested inside of this object, cloning the object in the process. If the input is unresolved (TaskInput::is_resolved) a “local” resolution task is created that runs this method.

Source

fn is_resolved(&self) -> bool

This should return true if there are any unresolved Vcs in the type.

Note that Vcs can sometimes be internally resolved, so you should call Vc::is_resolved (or rely on the derive macro for this trait) instead of returning true for any Vc. ResolvedVc::is_resolved always returns true.

If this returns true, a “local” resolution task calling TaskInput::resolve_input will be spawned before the function accepting the arguments is run.

If this returns false, the TaskInput will be cloned instead of resolved, and the function’s task will be spawned directly without a resolution step.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl TaskInput for HashAlgorithm

Source§

impl TaskInput for bool

Source§

impl TaskInput for i32

Source§

impl TaskInput for u8

Source§

impl TaskInput for u16

Source§

impl TaskInput for u32

Source§

impl TaskInput for u64

Source§

impl TaskInput for ()

Source§

impl TaskInput for usize

Source§

impl TaskInput for RcStr

Source§

impl TaskInput for String

Source§

impl TaskInput for Duration

Source§

impl<A> TaskInput for (A,)
where A: TaskInput,

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

impl<A, B> TaskInput for (A, B)
where A: TaskInput, B: TaskInput,

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

impl<A, B, C> TaskInput for (A, B, C)
where A: TaskInput, B: TaskInput, C: TaskInput,

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

impl<A, B, C, D> TaskInput for (A, B, C, D)
where A: TaskInput, B: TaskInput, C: TaskInput, D: TaskInput,

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

impl<A, B, C, D, E> TaskInput for (A, B, C, D, E)
where A: TaskInput, B: TaskInput, C: TaskInput, D: TaskInput, E: TaskInput,

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

impl<A, B, C, D, E, F> TaskInput for (A, B, C, D, E, F)

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

impl<A, B, C, D, E, F, G> TaskInput for (A, B, C, D, E, F, G)

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

impl<A, B, C, D, E, F, G, H> TaskInput for (A, B, C, D, E, F, G, H)

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

impl<A, B, C, D, E, F, G, H, I> TaskInput for (A, B, C, D, E, F, G, H, I)

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

impl<A, B, C, D, E, F, G, H, I, J> TaskInput for (A, B, C, D, E, F, G, H, I, J)

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

impl<A, B, C, D, E, F, G, H, I, J, K> TaskInput for (A, B, C, D, E, F, G, H, I, J, K)

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L> TaskInput for (A, B, C, D, E, F, G, H, I, J, K, L)

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

impl<K, V> TaskInput for FrozenMap<K, V>
where K: TaskInput + Ord + 'static, V: TaskInput + 'static,

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

impl<K, V> TaskInput for BTreeMap<K, V>
where K: TaskInput + Ord, V: TaskInput,

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

impl<T> TaskInput for Option<T>
where T: TaskInput,

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

impl<T> TaskInput for FrozenSet<T>
where T: TaskInput + Ord + 'static,

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

impl<T> TaskInput for Box<T>
where T: TaskInput,

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

impl<T> TaskInput for BTreeSet<T>
where T: TaskInput + Ord,

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

impl<T> TaskInput for Arc<T>
where T: TaskInput,

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

async fn resolve_input(&self) -> Result<Self>

Source§

impl<T> TaskInput for Vec<T>
where T: TaskInput,

Source§

fn is_resolved(&self) -> bool

Source§

fn is_transient(&self) -> bool

Source§

async fn resolve_input(&self) -> Result<Self>

Implementors§

Source§

impl TaskInput for TaskId

Source§

impl TaskInput for ValueTypeId

Source§

impl<L, R> TaskInput for EitherTaskInput<L, R>
where L: TaskInput, R: TaskInput,

Source§

impl<T> TaskInput for OperationVc<T>
where T: ?Sized + Send + Sync,

Source§

impl<T> TaskInput for ReadRef<T>
where T: TaskInput,

Source§

impl<T> TaskInput for ResolvedVc<T>
where T: Send + Sync + ?Sized,

Source§

impl<T> TaskInput for TransientInstance<T>
where T: Sync + Send + TraceRawVcs + 'static,

Source§

impl<T> TaskInput for TransientValue<T>
where T: MagicAny + Clone + Debug + Hash + Eq + TraceRawVcs + 'static,

Source§

impl<T> TaskInput for Vc<T>
where T: Send + Sync + ?Sized,