Skip to content

Commit aa1f48a

Browse files
committed
Discourage comparing str with Encoding using PartialEq
1 parent e74d4f7 commit aa1f48a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

objc2-encode/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1111
`Encoding::equivalent_to_start_of_str` methods for more precise comparison
1212
semantics.
1313

14+
### Changed
15+
* Discourage comparing `str` with `Encoding` using `PartialEq`. This trait
16+
impl might get removed in a future version.
17+
1418

1519
## 2.0.0-beta.0 - 2021-11-22
1620

objc2-encode/src/encoding.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,38 @@ impl fmt::Display for Encoding<'_> {
195195
}
196196
}
197197

198+
// TODO: Deprecate and remove these PartialEq impls
199+
200+
/// Partial equality between an [`Encoding`] and a [`str`].
201+
///
202+
/// Using this is heavily discouraged, since it is not transitive; use
203+
/// [`Encoding::equivalent_to_str`] instead for more correct semantics.
198204
impl PartialEq<str> for Encoding<'_> {
205+
/// Using this is discouraged.
199206
fn eq(&self, other: &str) -> bool {
200207
self.equivalent_to_str(other)
201208
}
209+
210+
/// Using this is discouraged.
211+
fn ne(&self, other: &str) -> bool {
212+
!self.eq(other)
213+
}
202214
}
203215

216+
/// Partial equality between an [`Encoding`] and a [`str`].
217+
///
218+
/// Using this is heavily discouraged, since it is not transitive; use
219+
/// [`Encoding::equivalent_to_str`] instead for more correct semantics.
204220
impl PartialEq<Encoding<'_>> for str {
221+
/// Using this is discouraged.
205222
fn eq(&self, other: &Encoding<'_>) -> bool {
206223
other.equivalent_to_str(self)
207224
}
225+
226+
/// Using this is discouraged.
227+
fn ne(&self, other: &Encoding<'_>) -> bool {
228+
!self.eq(other)
229+
}
208230
}
209231

210232
#[cfg(test)]

0 commit comments

Comments
 (0)