Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ImSoZRious opened this issue Jun 15, 2023 · 0 comments
Open

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

ImSoZRious opened this issue Jun 15, 2023 · 0 comments

Comments

@ImSoZRious
Copy link
Member

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 {
  ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant