Merge pull request #2317 from EugenDueck/patch-1

try_from_into.rs: Improve slice implementation
This commit is contained in:
Remo Senekowitsch 2026-05-11 09:28:06 +02:00 committed by GitHub
commit fd237df59a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -52,13 +52,12 @@ impl TryFrom<&[i16]> for Color {
type Error = IntoColorError; type Error = IntoColorError;
fn try_from(slice: &[i16]) -> Result<Self, Self::Error> { fn try_from(slice: &[i16]) -> Result<Self, Self::Error> {
// Check the length. if let &[red, green, blue] = slice {
if slice.len() != 3 {
return Err(IntoColorError::BadLen);
}
// Reuse the implementation for a tuple. // Reuse the implementation for a tuple.
Self::try_from((slice[0], slice[1], slice[2])) Self::try_from((red, green, blue))
} else {
Err(IntoColorError::BadLen)
}
} }
} }