How does comparison of a slice with an array work in Rust?

Viewed 1779

Why would [1,1] == &[1,1] not even compile (presumably because they're different types), yet the following snippet compiles and runs fine.

let a: [i32; 100] = [1; 100];
let b: &[i32] = &a[1..3];
if b == [1, 1] { // comparison with &[1, 1] works as well
    println!("it works"); // this does get printed
}
1 Answers
Related