Hi all,
I'm looking for a partial move operation when dealing with lambdas.
I have an operating involving an mpsc::channel
. As Sender<T>: !Copy
, I need to use the move
keyword to use it in the lambda:
let sender = self.sender.clone();
fn_using_lambda(mo ve || {
sender.send(...)
});
But by doing this, I'm forcing values which exist on self
to be moved into the closure as well.
struct x<T> where T: Clone {
sender: mpsc::Sender<T>
default: T
}
impl<T> x<T> where T: Clone {
fn use() {
let sender = self.sender.clone();
fn_using_lambda(move || {
sender.send(self.default.clone())
});
println!("{:?}", self.default);
}
}
This results in a use after move error.
My question: Is there a partial move operation, so I can specify that sender
should be moved, but self
should not?
Thanks so much
Jake