use super::config::{CompileCx, ConfigField, FieldKind, Resolver, Visit};
use super::expr::Expr;
use super::path::Path;
use crate::base::Result;
use datavalue::OwnedDataValue;
use serde_json::Value;
#[derive(Debug)]
pub struct Output(Expr<Path>);
impl Output {
pub fn path(&self) -> &Expr<Path> {
&self.0
}
pub fn constant(&self) -> Option<&Path> {
self.0.constant()
}
}
impl ConfigField for Output {
const IS_OUTPUT: bool = true;
fn compile(raw: &Value, cx: &mut CompileCx<'_>) -> Option<Self> {
<Expr<Path>>::compile(raw, cx).map(Self)
}
fn visit(&self, v: &mut Visit<'_>) {
v.recording(true, |v| v.expr(self.0.raw()));
}
fn resolve(&self, r: &mut dyn Resolver) -> Result<Option<OwnedDataValue>> {
r.eval(&self.0).map(Some)
}
fn kind() -> FieldKind {
FieldKind::Output
}
}