I'm trying to compare a rotation matrix from a file to a few knows rotation matrices, like this:
struct RotationMatrix;
impl RotationMatrix {
const NO_ROTATION: [u8; 36] = [
0, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0, 0, 0,
];
const ROTATION_90: [u8; 36] = [
0, 0, 0, 0, 0, 0x01, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0,
0, 0,
];
const ROTATION_180: [u8; 36] = [
0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40,
0, 0, 0,
];
const ROTATION_270: [u8; 36] = [
0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0, 0, 0, 0, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0,
0, 0,
];
}
let matrix_structure: Vec<u8> = file.read_to_end()?;
match data_from_file {
RotationMatrix::NO_ROTATION => { println!("No rotation") },
_ => println!("Some rotation"),
}
I get this:
--> src\rotate.rs:77:3
|
9 | const NO_ROTATION: [u8; 36] = [
| _____-
10 | | 0, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x40, 0, 0, 0,
11 | | ];
| |______- associated constant defined here
...
76 | match matrix_structure {
| ---------------- this expression has type `Vec<u8>`
77 | RotationMatrix::NO_ROTATION => println!("No rotation"),
| ^^^^^^^^^^^^^^^^-----------
| | |
| | help: introduce a new binding instead: `other_no_rotation`
| expected struct `Vec`, found array `[u8; 36]`
| `NO_ROTATION` is interpreted as an associated constant, not a new binding
|
= note: expected type `Vec<u8>`
found array `[u8; 36]`
How can I make this work? Feel free to store the known rotation matrices in a different type, this was just the first idea I came up with.