Skip to content

Commit 1b31c66

Browse files
fix: Implement PartialEq to do deep byte comparison
1 parent a1b389a commit 1b31c66

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Diff for: src/user.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,25 @@ impl Display for User {
149149
}
150150

151151
/// A structure that can either be a string or bytes
152-
#[derive(Clone, Debug, PartialEq)]
152+
#[derive(Clone, Debug)]
153153
pub(crate) enum StringOrBytes {
154154
/// A string
155155
String(String),
156156
/// A byte string
157157
Bytes(Vec<u8>),
158158
}
159159

160+
impl PartialEq for StringOrBytes {
161+
fn eq(&self, other: &Self) -> bool {
162+
match (self, other) {
163+
(Self::String(s), Self::String(o)) => s == o,
164+
(Self::String(s), Self::Bytes(o)) => s.as_bytes() == o,
165+
(Self::Bytes(s), Self::String(o)) => s == o.as_bytes(),
166+
(Self::Bytes(s), Self::Bytes(o)) => s == o,
167+
}
168+
}
169+
}
170+
160171
impl Display for StringOrBytes {
161172
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
162173
match self {

0 commit comments

Comments
 (0)