I can't get rid of an error on this code:
#[derive(PartialEq, Copy, Clone)]
pub enum OperationMode {
ECB,
CBC { iv: [u8; 16] },
}
pub struct AES {
key: Vec<u8>,
nr: u8,
mode: OperationMode,
}
impl AES {
pub fn decrypt(&mut self, input: &Vec<u8>) {
match self.mode {
OperationMode::ECB => {},
OperationMode::CBC(_) => {},
};
}
}
The pattern matching at the end of the decrypt
function gives an error:
error[E0532]: expected tuple struct/variant, found struct variant `OperationMode::CBC`
--> src/main.rs:17:13
|
17 | OperationMode::CBC(_) => {},
| ^^^^^^^^^^^^^^^^^^ did you mean `OperationMode::CBC { /* fields */ }`?
It tells me to look at the output of rustc --explain E0532
for help, which I did.
They show this example of wrong code:
enum State { Succeeded, Failed(String), } fn print_on_failure(state: &State) { match *state { // error: expected unit struct/variant or constant, found tuple // variant `State::Failed` State::Failed => println!("Failed"), _ => () } }
In this example, the error occurs because State::Failed
has a field which isn't matched. It should be State::Failed(ref msg)
.
In my case I'm matching the field of my enum because I'm doing OperationMode::CBC(_)
. Why does the error happen?