Those are good points and I'll take a look at the Self: 'a
and dyn ... + 'a
parameters again to simplify. Actually, I ended up adding those pursuant to an answer I helpfully got from you. I believe it was needed for one of the handlers I was dealing with.
You're right it's a lot to take in. For completeness sake I'll just post Transact
trait Transact<T> {
type State;
fn transact(self: Box<Self>, _: T) -> (Box<dyn Transact<T, State = Self::State> + Send>, Option<Transition<Self::State>>);
It's just an interface meant to model a sequence of protocol messages and their state-machine transitions
impl Transact<&Event> for (Message1) ...
impl Transact<&Event> for (Message1, Message2) ...
impl Transact<&Event> for (Message1, Timeout) ...
The issue with <T>
, and as you point out, on Transact
is that for some implementations I need to pass in an owned type so I can't restrict T to always be a reference type &T
in the argument. I don't think I need type erasure. I always know what T
is from the impl side and struct member containing Transact
side.