Switching things to tagged type

This commit is contained in:
2026-03-20 20:22:36 +01:00
parent 822cdc1587
commit ac5c9eeaa0
6 changed files with 254 additions and 154 deletions

View File

@ -2,12 +2,14 @@ use std::ops::{Add, Mul};
use oxydsp_flowgraph::{
BlockIO,
block::{Block, BlockResult},
block::{Block, BlockResult, SyncBlock},
io::{In, Out, PopIterable},
sync_block,
tag::TagMergable,
};
#[derive(BlockIO)]
#[sync_block]
pub struct Adder<Ia, Ib, O>
where
Ia: Add<Ib, Output = O> + 'static,
@ -44,23 +46,35 @@ where
}
}
impl<Ia, Ib, O> Block for Adder<Ia, Ib, O>
impl<'view, Ia, Ib, O> SyncBlock<'view> for Adder<Ia, Ib, O>
where
Ia: Add<Ib, Output = O> + 'static,
Ib: 'static,
O: 'static,
{
fn work(&mut self) -> BlockResult
fn sync_work(_state: Self::StateView, input: Self::Input) -> Option<Self::Output>
{
self.output.push_iter(
(&mut self.input_a, &mut self.input_b)
.pop_iter()
.map(|(a, b)| (a.0 + b.0, a.1.merge(&b.1))),
);
BlockResult::Ok
Some(input.0 + input.1)
}
}
// impl<Ia, Ib, O> Block for Adder<Ia, Ib, O>
// where
// Ia: Add<Ib, Output = O> + 'static,
// Ib: 'static,
// O: 'static,
// {
// fn work(&mut self) -> BlockResult
// {
// self.output.push_iter(
// (&mut self.input_a, &mut self.input_b)
// .pop_iter()
// .map(|(a, b)| (a.0 + b.0, a.1.merge(&b.1))),
// );
// BlockResult::Ok
// }
// }
#[derive(BlockIO)]
pub struct Multiplier<Ia, Ib, O>
where
@ -109,7 +123,7 @@ where
self.output.push_iter(
(&mut self.input_a, &mut self.input_b)
.pop_iter()
.map(|(a, b)| (a.0 * b.0, a.1.merge(&b.1))),
.map(|(a, b)| (a.0 * b.0, a.1.merge(&b.1)).into()),
);
BlockResult::Ok
}