From d21d0809299bec098eff22d9b0a629d7bdd4a639 Mon Sep 17 00:00:00 2001 From: Voxell Paladynee Date: Sat, 16 May 2026 06:54:47 +0200 Subject: [PATCH] optimize PartialEq for Cow, delegate to &str Display implementation directly instead of generating code, fix a typo --- src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d68a892..f0a7933 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -208,7 +208,7 @@ impl Ord for Ustr { /// Defer to `str` for equality. /// -/// Lexicographic ordering will be slower thanpointer comparison, but much less +/// Lexicographic ordering will be slower than pointer comparison, but much less /// surprising if you use `Ustr`s as keys in e.g. a `BTreeMap`. #[allow(clippy::non_canonical_partial_ord_impl)] impl PartialOrd for Ustr { @@ -451,25 +451,25 @@ impl PartialEq for &Box { impl PartialEq> for Ustr { fn eq(&self, other: &Cow<'_, str>) -> bool { - self.as_str() == &*other + self.as_str() == &**other } } impl PartialEq for Cow<'_, str> { fn eq(&self, u: &Ustr) -> bool { - &*self == u.as_str() + &**self == u.as_str() } } impl PartialEq<&Cow<'_, str>> for Ustr { fn eq(&self, other: &&Cow<'_, str>) -> bool { - self.as_str() == &**other + self.as_str() == &***other } } impl PartialEq for &Cow<'_, str> { fn eq(&self, u: &Ustr) -> bool { - &**self == u.as_str() + &***self == u.as_str() } } @@ -610,7 +610,7 @@ impl Deref for Ustr { impl fmt::Display for Ustr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.as_str()) + ::fmt(self.as_str(), f) } }