-
Notifications
You must be signed in to change notification settings - Fork 628
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
Implement Clone on With combinator #2290
Implement Clone on With combinator #2290
Conversation
Consider the following use-case of mpsc channels. There are two categories of producers which produce items of two distinct types, later unified in one using `With` combinator: ``` let (sender, receiver) = mspc::channel(100); let download_status = sender.clone().with(|item| { futures::future::ok(Status::Download(item)) }); let unpack_status = sender.clone().with(|item| { futures::future::ok(Status::Unpack(item)) }); ``` It would be convenient for `With` combinator to implement `Clone`, since the underlying sink, `futures::channel::mpsc::Sender`, implements it. This change adds `#[derive(Clone)]` to `With` combinator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. derive is not the better way to do this, as that adds U: Clone, Item: Clone
bounds. Could you use manual impl instead of deriving?
Address review comments This change * Implements `Clone` for `With` manually since we don't want to have `U: Clone, Item: Clone` bounds. * Adds a test case for `Clone` implementation.
Thanks for the review.
Sure thing, please see the update. Also, I'm not familiar with the code style of the project, so please feel free to point out any slipups. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks
Consider the following use-case of mpsc channels. There are two categories of producers which produce items of two distinct types, later unified in one using `With` combinator: ``` let (sender, receiver) = mspc::channel(100); let download_status = sender.clone().with(|item| { futures::future::ok(Status::Download(item)) }); let unpack_status = sender.clone().with(|item| { futures::future::ok(Status::Unpack(item)) }); ``` It would be convenient for `With` combinator to implement `Clone`, since the underlying sink, `futures::channel::mpsc::Sender`, implements it.
Consider the following use-case of mpsc channels. There are two
categories of producers which produce items of two distinct types,
later unified in one using
With
combinator:It would be convenient for
With
combinator to implementClone
,since the underlying sink,
futures::channel::mpsc::Sender
,implements it.
This change adds
#[derive(Clone)]
toWith
combinator