I am trying to model my application sort of like transducer like framework. And I am kind of stuck on how I can dynamically compose them based on user input.
struct Compose<Left, Right, L, R, F> {
left: Left,
right: Right,
fn: F,
_l: std::marker::PhantomData<L>,
_r: std::marker::PhantomData<R>,
}
trait TestPull<T> {
type State;
fn initial(&self) -> Self::State;
fn next(&self, state: &Self::State) -> T;
}
fn compose<Left, Right, L, R, F>(left: Left, right: Right, func: F) -> Compose<Left, Right, L, R, F>
where
Left: TestPull<L>,
Right: TestPull<R>,
{
Compose {
left,
right,
func,
_l: std::marker::PhantomData,
_r: std::marker::PhantomData,
}
}
impl<Left, Right, L, R> TestPull<(L, R)> for Compose<Left, Right, L, R>
where
Left: TestPull<L>,
Right: TestPull<R>,
{
fn initial(&self) -> (Left::State, Right::State) {
(self.left.initial(), self.right.initial())
}
fn next(&self, state: &(Left::State, Right::State)) -> (L, R) {
(self.left.next(&state.0), self.right.next(&state.1))
}
}
fn less<L, R>(left: dyn TestPull<L>, right: dyn TestPull<R>) {
compose(left, right, |l, r| l < r)
}
The less
fails with the Self::State
should be specified error. I understand there is no way to get it working without that, I am kind of not getting any direction on how I can model this without the state field. I am losing my sleep over this