Skip to content

Use Listener<P> instead of Listener<Data = P> #5

@plohan

Description

@plohan

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 {
  ...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions