Flip lazy-input nodes onto record wires through the element lazy input

This commit is contained in:
Dennis Kobert
2026-08-05 23:12:43 +00:00
parent c20a243fc2
commit 7ddc66adbe
2 changed files with 59 additions and 2 deletions

View File

@@ -282,6 +282,44 @@ where
}
}
/// A record edge at a caller-chosen lifetime; the lifetime is a trait
/// parameter for the same constrained-position reason as
/// [`DerivedRecordEdge`].
pub trait RecordEdge<'e, C>: Node<C, Output = RecordValue<'e>> {}
impl<'e, C, N: Node<C, Output = RecordValue<'e>>> RecordEdge<'e, C> for N {}
/// The lazy input handed to a kernel whose edge rides a record wire while
/// the kernel consumes the plain element.
#[derive(Clone, Copy)]
pub struct ElementLazyInput<'a, El, N> {
node: &'a N,
cell: &'a crate::node::StatusCell,
input_index: usize,
layout: &'a Layout,
_marker: std::marker::PhantomData<fn() -> El>,
}
impl<'a, El: Clone, N> ElementLazyInput<'a, El, N> {
pub fn new(node: &'a N, cell: &'a crate::node::StatusCell, input_index: usize, layout: &'a Layout) -> Self {
Self {
node,
cell,
input_index,
layout,
_marker: std::marker::PhantomData,
}
}
pub fn eval<'d, C>(&self, ctx: &C) -> Result<El, crate::gpoll::Interrupt>
where
N: Node<C, Output = RecordValue<'d>>,
{
let value = self.cell.eval_input(self.input_index, self.node, ctx)?;
Ok(unsafe { read_element::<El>(self.layout.rec(&value)) })
}
}
/// The lazy record input handed to a kernel that evaluates its edges under
/// derived contexts: evaluating rebinds the record to the kernel's routing
/// lifetime, so the value escapes the derivation scope.