Equality of array and vector is not symmetric

Hi, folks,

I bumped into this today where equality of array and vec is not symmetric. The code below doesn't compile, but if you reverse it to say b == a then it does compile.

This is quite surprising to me. There is a mention here: rust/partial_eq.rs at e4c23daeb461ac02413eb36c8cefcc5530638a05 · rust-lang/rust · GitHub

about code bloat, but is that true anymore with the latest "const generics"?


fn main() {

    let a = [1, 2, 3];
    let b = vec![1, 2, 3];
    let c = a == b;
    println!("a: {:?}", a);
    println!("b: {:?}", b);
    println!("c: {:?}", c);


1 Like

True, it shouldn't be so bad anymore -- could be worth trying it!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.