From 21952961d323915b4abcf46b479d4df2c0d04992 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Sat, 7 Dec 2024 22:14:57 +0700 Subject: [PATCH] Simplify type bounds on `Setting`, not always `Eq` (#77) This makes `swash::Setting` more like `skrifa::setting::Setting`. It is only `Eq` when the underlying type is `Eq`, so not for `Setting`. It doesn't need to always state that it is `Copy`, so only state that when needed. The impl of `PartialEq` can be derived. --- src/setting.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/setting.rs b/src/setting.rs index ce899c4..b1e9453 100644 --- a/src/setting.rs +++ b/src/setting.rs @@ -2,23 +2,15 @@ use super::{tag_from_bytes, tag_from_str_lossy, Tag}; use core::fmt; /// Setting combining a tag and a value for features and variations. -#[derive(Copy, Clone, Default, Debug)] -pub struct Setting { +#[derive(Copy, Clone, Default, Debug, PartialEq, Eq)] +pub struct Setting { /// The tag that identifies the setting. pub tag: Tag, /// The value for the setting. pub value: T, } -impl PartialEq for Setting { - fn eq(&self, other: &Self) -> bool { - self.tag == other.tag && self.value == other.value - } -} - -impl Eq for Setting {} - -impl fmt::Display for Setting { +impl fmt::Display for Setting { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let bytes = self.tag.to_be_bytes(); let tag_name = core::str::from_utf8(&bytes).unwrap_or(""); @@ -74,7 +66,7 @@ impl Setting { } } -impl From<(Tag, T)> for Setting { +impl From<(Tag, T)> for Setting { fn from(v: (Tag, T)) -> Self { Self { tag: v.0, @@ -110,7 +102,7 @@ impl From<&(&[u8; 4], T)> for Setting { } } -impl From<(&str, T)> for Setting { +impl From<(&str, T)> for Setting { fn from(v: (&str, T)) -> Self { Self { tag: tag_from_str_lossy(v.0),