diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2025-08-03 12:47:11 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2025-08-03 12:47:11 -0700 |
| commit | eee28138b89902426815a0d9dd96800c686f5003 (patch) | |
| tree | 2f64ac021f68704bc086fac7d96af9b47bce391a | |
| parent | 63f6845e570305a92eaf855897768617366164d6 (diff) | |
| download | rust-eee28138b89902426815a0d9dd96800c686f5003.tar.gz rust-eee28138b89902426815a0d9dd96800c686f5003.zip | |
Use `as_array` in PartialEq for arrays
| -rw-r--r-- | library/core/src/array/equality.rs | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/library/core/src/array/equality.rs b/library/core/src/array/equality.rs index bb668d2a673..1ad2cca64a3 100644 --- a/library/core/src/array/equality.rs +++ b/library/core/src/array/equality.rs @@ -22,18 +22,16 @@ where { #[inline] fn eq(&self, other: &[U]) -> bool { - let b: Result<&[U; N], _> = other.try_into(); - match b { - Ok(b) => *self == *b, - Err(_) => false, + match other.as_array::<N>() { + Some(b) => *self == *b, + None => false, } } #[inline] fn ne(&self, other: &[U]) -> bool { - let b: Result<&[U; N], _> = other.try_into(); - match b { - Ok(b) => *self != *b, - Err(_) => true, + match other.as_array::<N>() { + Some(b) => *self != *b, + None => true, } } } @@ -45,18 +43,16 @@ where { #[inline] fn eq(&self, other: &[U; N]) -> bool { - let b: Result<&[T; N], _> = self.try_into(); - match b { - Ok(b) => *b == *other, - Err(_) => false, + match self.as_array::<N>() { + Some(b) => *b == *other, + None => false, } } #[inline] fn ne(&self, other: &[U; N]) -> bool { - let b: Result<&[T; N], _> = self.try_into(); - match b { - Ok(b) => *b != *other, - Err(_) => true, + match self.as_array::<N>() { + Some(b) => *b != *other, + None => true, } } } |
