2

I have the following code:

enum State {
    Foo(Vec<u8>),
    Bar(Vec<u8>),
}

struct Test {
    state: State,
}

impl Test {
    fn to_bar(&mut self) {
        // change the state from foo to bar
        match &self.state {
            &State::Foo(v) => {self.state = State::Bar(v)},
            State::Bar(_) => ()
        }
    }
}

I get a data move error, but I don't understand why it is not possible.

Am I missing something ?

Is what I'm trying to do against rust safety model ?

rambi
  • 1,013
  • 1
  • 7
  • 25

0 Answers0