diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2025-08-05 03:51:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-05 03:51:38 +0200 |
| commit | db7ac64997bcf1c5b6e86a403725f7b0c0360fda (patch) | |
| tree | 9294955097862e946dee640d32942ce4d42f60c7 | |
| parent | 149ee59876d06e60ea5b2390ddfb537b42f9d6ba (diff) | |
| parent | eee28138b89902426815a0d9dd96800c686f5003 (diff) | |
| download | rust-db7ac64997bcf1c5b6e86a403725f7b0c0360fda.tar.gz rust-db7ac64997bcf1c5b6e86a403725f7b0c0360fda.zip | |
Rollup merge of #144867 - scottmcm:more-as-array, r=chenyukang
Use `as_array` in PartialEq for arrays Now that `as_array` exists we might as well use it here, since it's a bit more convenient than getting the correct type out of `try_into`.
| -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, } } } |
