The current trait use associate type to correlate between listener and intermediate payload.
pub trait Listener: Send + Sync {
type Data;
type S: Stream<Item = Self::Data> + Unpin + Send;
fn into_stream(self) -> Self::S;
}
This is suboptimal design. For example, let's say that raw payload from listener L can be turn into intermediate payload P (Data = P). Which mean
impl Listener for L {
type Data = P;
...
}
Then, with this approach, it is not possible to make that listener to turn into other intermediate payload.
pub trait Listener<P>: Send + Sync {
type S: Stream<Item = P> + Unpin + Send;
fn into_stream(self) -> Self::S;
}
With this implementation, it is possible to implement many intermediate payload for one type of listener.
impl Listener<P1> for L {
...
}
impl Listener<P2> for L {
...
}
The current trait use associate type to correlate between listener and intermediate payload.
This is suboptimal design. For example, let's say that raw payload from listener
Lcan be turn into intermediate payloadP(Data = P). Which meanThen, with this approach, it is not possible to make that listener to turn into other intermediate payload.
With this implementation, it is possible to implement many intermediate payload for one type of listener.