Skip to content

Commit

Permalink
implement PartialEq<str> for string new types
Browse files Browse the repository at this point in the history
  • Loading branch information
ModProg committed Aug 26, 2024
1 parent 03a3604 commit 83802bf
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions dbus/src/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ impl<'m> hash::Hash for $t<'m> {
}
}

impl PartialEq<str> for $t<'_> {
fn eq(&self, other: &str) -> bool {
&**self == other
}
}

impl PartialEq<&'_ str> for $t<'_> {
fn eq(&self, other: &&str) -> bool {
&**self == *other
}
}

}}

/// A wrapper around a string that is guaranteed to be
Expand Down Expand Up @@ -248,3 +260,10 @@ fn reborrow_path() {
fn make_sig() {
assert_eq!(&*Signature::make::<(&str, u8)>(), "(sy)");
}

#[test]
fn partial_eq_str() {
assert_eq!(Signature::new("s").unwrap(), "s");
assert!(Signature::new("s").unwrap() != "s\0");
assert_eq!(Path::new("/hello").unwrap(), "/hello");
}

0 comments on commit 83802bf

Please sign in to comment.