use super::{Deserialize, Serialize};
use crate::node::{self, Node};
use steel::{parser::ast::ExprKind, steel_vm::engine::Engine};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Push<N> {
node: N,
conf: node::EvalConf,
}
pub trait WithPushEval: Sized + Node {
fn with_push_eval_conf(self, conf: node::EvalConf) -> Push<Self>;
fn with_push_eval(self) -> Push<Self> {
self.with_push_eval_conf(node::EvalConf::All)
}
}
impl<N> Push<N>
where
N: Node,
{
pub fn all(node: N) -> Self {
Push::new(node, node::EvalConf::All)
}
pub fn new(node: N, conf: node::EvalConf) -> Self {
Push { node, conf }
}
}
impl<N> WithPushEval for N
where
N: Node,
{
fn with_push_eval_conf(self, conf: node::EvalConf) -> Push<Self> {
Push::new(self, conf)
}
}
impl<N> Node for Push<N>
where
N: Node,
{
fn n_inputs(&self) -> usize {
self.node.n_inputs()
}
fn n_outputs(&self) -> usize {
self.node.n_outputs()
}
fn branches(&self) -> Vec<node::EvalConf> {
self.node.branches()
}
fn expr(&self, ctx: node::ExprCtx) -> ExprKind {
self.node.expr(ctx)
}
fn push_eval(&self) -> Vec<node::EvalConf> {
vec![self.conf.clone()]
}
fn pull_eval(&self) -> Vec<node::EvalConf> {
self.node.pull_eval()
}
fn inlet(&self) -> bool {
self.node.inlet()
}
fn outlet(&self) -> bool {
self.node.outlet()
}
fn stateful(&self) -> bool {
self.node.stateful()
}
fn register(&self, path: &[node::Id], vm: &mut Engine) {
self.node.register(path, vm)
}
}