Skip to content

Commit f468861

Browse files
committed
refactor: simplify byte slice comparison in ZString implementation
1 parent 2fb9bf8 commit f468861

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

phper/src/strings.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,7 @@ impl AsRef<[u8]> for ZString {
235235

236236
impl<Rhs: AsRef<[u8]>> PartialEq<Rhs> for ZString {
237237
fn eq(&self, other: &Rhs) -> bool {
238-
let this: &[u8] = self.as_ref();
239-
this == other.as_ref()
238+
AsRef::<[u8]>::as_ref(self) == other.as_ref()
240239
}
241240
}
242241

tests/integration/src/strings.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ pub fn integrate(module: &mut Module) {
1818
assert_eq!(zs.to_str()?, "hello");
1919

2020
let zs = ZString::new([1, 2, 3]);
21-
let zs: &[u8] = zs.as_ref();
22-
assert_eq!(zs, &[1, 2, 3]);
21+
assert_eq!(AsRef::<[u8]>::as_ref(&zs), &[1, 2, 3]);
2322

2423
assert!(ZString::new("hello") == ZString::new(b"hello"));
2524

@@ -34,8 +33,7 @@ pub fn integrate(module: &mut Module) {
3433
assert_eq!(zs.to_str()?, "persistent_hello");
3534

3635
let zs = ZString::new_persistent([4, 5, 6]);
37-
let zs: &[u8] = zs.as_ref();
38-
assert_eq!(zs, &[4, 5, 6]);
36+
assert_eq!(AsRef::<[u8]>::as_ref(&zs), &[4, 5, 6]);
3937

4038
assert!(
4139
ZString::new_persistent("persistent") == ZString::new_persistent(b"persistent")

0 commit comments

Comments
 (0)