arrayvec icon indicating copy to clipboard operation
arrayvec copied to clipboard

Add PartialEq implementations

Open stepantubanov opened this issue 3 years ago • 0 comments

This allows nested comparisons:

fn test_nested_eq() {
    let array: ArrayVec<ArrayVec<_, 2>, 5> = (0..3)
        .map(|i| ArrayVec::from([i, i + 1]))
        .collect();

    assert_eq!(array, [[0, 1], [1, 2], [2, 3]]);
}

fn test_vec_of_strings_equality() {
    let vec = ArrayVec::from([
        ArrayString::<8>::from("one").unwrap(),
        ArrayString::<8>::from("two").unwrap(),
        ArrayString::<8>::from("three").unwrap(),
    ]);
    assert_eq!(vec, ["one", "two", "three"]);
}

Implementation is similar to std https://doc.rust-lang.org/src/alloc/vec/partial_eq.rs.html#7

stepantubanov avatar Mar 10 '22 01:03 stepantubanov