Implement PartialEq and Eq for image::Bytes

This commit is contained in:
Héctor Ramón Jiménez 2023-04-05 05:47:29 +02:00
parent f8cd1faa28
commit 4cae262d22
No known key found for this signature in database
GPG key ID: 140CC052C94F138E

View file

@ -110,6 +110,14 @@ impl std::hash::Hash for Bytes {
}
}
impl PartialEq for Bytes {
fn eq(&self, other: &Self) -> bool {
self.as_ref() == other.as_ref()
}
}
impl Eq for Bytes {}
impl AsRef<[u8]> for Bytes {
fn as_ref(&self) -> &[u8] {
self.0.as_ref().as_ref()
@ -125,7 +133,7 @@ impl std::ops::Deref for Bytes {
}
/// The data of a raster image.
#[derive(Clone, Hash)]
#[derive(Clone, PartialEq, Eq, Hash)]
pub enum Data {
/// File data
Path(PathBuf),
@ -156,34 +164,6 @@ impl std::fmt::Debug for Data {
}
}
impl PartialEq for Data {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Path(a), Self::Path(b)) => a == b,
(Self::Bytes(a), Self::Bytes(b)) => a.as_ref() == b.as_ref(),
(
Self::Rgba {
width: width_a,
height: height_a,
pixels: pixels_a,
},
Self::Rgba {
width: width_b,
height: height_b,
pixels: pixels_b,
},
) => {
width_a == width_b
&& height_a == height_b
&& pixels_a.as_ref() == pixels_b.as_ref()
}
_ => false,
}
}
}
impl Eq for Data {}
/// A [`Renderer`] that can render raster graphics.
///
/// [renderer]: crate::renderer