Skip to content

Commit e399a5b

Browse files
committed
Impl PartialEq<str> for Tendril
Signed-off-by: Nico Burns <[email protected]>
1 parent d242885 commit e399a5b

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

tendril/src/tendril.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,13 @@ where
468468
}
469469
}
470470

471+
impl<F: fmt::Format, A: Atomicity> PartialEq<str> for Tendril<F, A> {
472+
#[inline]
473+
fn eq(&self, other: &str) -> bool {
474+
self.as_byte_slice() == other.as_bytes()
475+
}
476+
}
477+
471478
impl<F, A> Eq for Tendril<F, A>
472479
where
473480
F: fmt::Format,
@@ -2333,19 +2340,22 @@ mod test {
23332340
let bytes_expected = bytes.to_tendril();
23342341

23352342
// char
2336-
assert_eq!(string_expected, string.chars().collect());
2343+
assert_eq!(string_expected, string.chars().collect::<Tendril<_>>());
23372344
let mut tendril = StrTendril::new();
23382345
tendril.extend(string.chars());
23392346
assert_eq!(string_expected, tendril);
23402347

23412348
// &u8
2342-
assert_eq!(bytes_expected, bytes.iter().collect());
2349+
assert_eq!(bytes_expected, bytes.iter().collect::<Tendril<_>>());
23432350
let mut tendril = ByteTendril::new();
23442351
tendril.extend(bytes);
23452352
assert_eq!(bytes_expected, tendril);
23462353

23472354
// u8
2348-
assert_eq!(bytes_expected, bytes.iter().copied().collect());
2355+
assert_eq!(
2356+
bytes_expected,
2357+
bytes.iter().copied().collect::<Tendril<_>>()
2358+
);
23492359
let mut tendril = ByteTendril::new();
23502360
tendril.extend(bytes.iter().copied());
23512361
assert_eq!(bytes_expected, tendril);

0 commit comments

Comments
 (0)