I'm relatively new to Rust language and trying to do something like:
pub const ARR_SIZE: usize = 3;
fn main() {
pub const ARR: [&str; ARR_SIZE] = [
"Does",
"This",
"Work"
];
println!("{}",ARR[0]);
assert_eq!("Does", ARR[0]); // This does work
let k = format!("{}", ARR[0]);
println!("{}",k);
assert_eq!(k, ARR[0].); // This does work
let p = "Does";
match p {
ARR[0] => true, // This does not work; does not compile.
_ => false
};
}
The intent is to pattern match the slices in ARR
with values p
that are passed in.
Is there a syntax I'm missing for destructuring const arrays? Is there a reason this would cause problems?