binius_m3/builder/
test_utils.rs1use anyhow::Result;
6use binius_field::{PackedField, TowerField};
7
8use crate::builder::{TableFiller, TableId, TableWitnessSegment};
9
10#[allow(clippy::type_complexity)]
15pub struct ClosureFiller<'a, P, Event>
16where
17 P: PackedField,
18 P::Scalar: TowerField,
19{
20 table_id: TableId,
21 fill: Box<dyn for<'b> Fn(&'b [&'b Event], &'b mut TableWitnessSegment<P>) -> Result<()> + 'a>,
22}
23
24impl<'a, P: PackedField<Scalar: TowerField>, Event> ClosureFiller<'a, P, Event> {
25 pub fn new(
26 table_id: TableId,
27 fill: impl for<'b> Fn(&'b [&'b Event], &'b mut TableWitnessSegment<P>) -> Result<()> + 'a,
28 ) -> Self {
29 Self {
30 table_id,
31 fill: Box::new(fill),
32 }
33 }
34}
35
36impl<P: PackedField<Scalar: TowerField>, Event: Clone> TableFiller<P>
37 for ClosureFiller<'_, P, Event>
38{
39 type Event = Event;
40
41 fn id(&self) -> TableId {
42 self.table_id
43 }
44
45 fn fill<'b>(
46 &'b self,
47 rows: impl Iterator<Item = &'b Self::Event> + Clone,
48 witness: &'b mut TableWitnessSegment<P>,
49 ) -> Result<()> {
50 (*self.fill)(&rows.collect::<Vec<_>>(), witness)
51 }
52}