Skip to content

equals_unordered

Returns true when a and b hold the same elements the same number of times, in any order.

Use it for collections where order is meaningless (tags, ids). For positional equality, compare the slices with ==.

use helpers4::array::equals_unordered;

Cargo feature array (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features array

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.5", default-features = false, features = ["array"] }
pub fn equals_unordered<T: Eq + Hash>(a: &[T], b: &[T]) -> bool
ParameterTypeDescription
a&[T]The first slice.
b&[T]The second slice.

bool

use helpers4::array::equals_unordered;

assert!(equals_unordered(&[1, 2, 2, 3], &[3, 2, 1, 2]));
assert!(!equals_unordered(&[1, 2, 2], &[1, 1, 2]));

src/array/equals_unordered.rs