Looking for a partial-move operation in rust

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

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

    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

Move is all or nothing. Take references before the closure and move those, instead.

1 Like

Ah of course... Thankss

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.