File size: 935 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
use std::marker::PhantomData;
use anyhow::Result;
use crate::{RawVc, Vc};
/// Trait to implement in order for a type to be accepted as a
/// `turbo_tasks::function` return type.
pub trait TaskOutput: Send {
type Return: ?Sized;
fn try_from_raw_vc(raw_vc: RawVc) -> Vc<Self::Return> {
Vc {
node: raw_vc,
_t: PhantomData,
}
}
fn try_into_raw_vc(self) -> Result<RawVc>;
}
impl<T> TaskOutput for Vc<T>
where
T: Send + ?Sized,
{
type Return = T;
fn try_into_raw_vc(self) -> Result<RawVc> {
Ok(self.node)
}
}
impl TaskOutput for () {
type Return = ();
fn try_into_raw_vc(self) -> Result<RawVc> {
let unit = Vc::<()>::default();
Ok(unit.node)
}
}
impl<T> TaskOutput for Result<T>
where
T: TaskOutput,
{
type Return = T::Return;
fn try_into_raw_vc(self) -> Result<RawVc> {
self?.try_into_raw_vc()
}
}
|