Skip to content

Commit

Permalink
🐛 zv: Do not derive Eq for Signature
Browse files Browse the repository at this point in the history
As per [`Eq`](https://doc.rust-lang.org/stable/std/cmp/trait.Eq.html#derivable)
docs on deriving: "Note that the derive strategy requires all fields are `Eq,
 which isn’t always desired."

We specify conditional `Signature` equality that does not include all
fields are (derivable) `Eq`.

This is why `Eq` for `Signature` is manually implemented.
  • Loading branch information
luukvanderduim committed Aug 14, 2023
1 parent 76b9944 commit 89b42ad
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion zvariant/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<'b> std::ops::Deref for Bytes<'b> {
///
/// [identifies]: https://dbus.freedesktop.org/doc/dbus-specification.html#type-system
/// [`slice`]: #method.slice
#[derive(Eq, Hash, Clone)]
#[derive(Hash, Clone)]
pub struct Signature<'a> {
bytes: Bytes<'a>,
pos: usize,
Expand Down Expand Up @@ -445,6 +445,10 @@ impl<'a> PartialEq<&str> for Signature<'a> {
}
}

// According to the docs, `Eq` derive should only be used on structs if all its fields are
// are `Eq`. Hence the manual implementation.
impl Eq for Signature<'_> {}

impl<'a> Display for Signature<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
std::fmt::Display::fmt(&self.as_str(), f)
Expand Down

0 comments on commit 89b42ad

Please sign in to comment.