turbo_tasks/
output.rs

1use std::fmt::{self, Display};
2
3use anyhow::anyhow;
4
5use crate::{RawVc, backend::TurboTasksExecutionError};
6
7/// A helper type representing the output of a resolved task.
8#[derive(Clone, Debug)]
9pub enum OutputContent {
10    Link(RawVc),
11    Error(TurboTasksExecutionError),
12}
13
14impl OutputContent {
15    pub fn as_read_result(&self) -> anyhow::Result<RawVc> {
16        match &self {
17            Self::Error(err) => Err(anyhow!(err.clone())),
18            Self::Link(raw_vc) => Ok(*raw_vc),
19        }
20    }
21}
22
23impl Display for OutputContent {
24    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25        match self {
26            Self::Link(raw_vc) => write!(f, "link {raw_vc:?}"),
27            Self::Error(err) => write!(f, "error {err}"),
28        }
29    }
30}