From 83802bfc110909bf69b809d449e56cb2a6f8ef4c Mon Sep 17 00:00:00 2001 From: Roland Fredenhagen Date: Sun, 25 Aug 2024 19:15:17 +0200 Subject: [PATCH] implement PartialEq for string new types --- dbus/src/strings.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/dbus/src/strings.rs b/dbus/src/strings.rs index 2b9544a..30c8e51 100644 --- a/dbus/src/strings.rs +++ b/dbus/src/strings.rs @@ -165,6 +165,18 @@ impl<'m> hash::Hash for $t<'m> { } } +impl PartialEq 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 @@ -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"); +}