Syntax to clone while destructuring?

Is there a way to do something like this?

struct Foo {
    bar: String,
    baz: String
}

impl Foo {
    fn run(&self) {
        // magic syntax so that bar and baz are cloned?
        //note, I do not want to clone all of Self, even if it were possible
        let Self { bar, baz } = self;
        
        pass(bar);
    }
}

fn pass(s:String) {
    
}

No, but you can destructure into references and clone the references on first use. (You're doing this here since self is a reference.)

1 Like

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.