-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement PartialEq<str> for String and Cow #23972
Conversation
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
@@ -826,6 +826,38 @@ impl_eq! { String, &'a str } | |||
impl_eq! { Cow<'a, str>, String } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, you can use &[..]
notation inside of impl_eq!
like #23521 does and reduce all the impls for Cow<'a, str>
, String
and str
to just a few lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the tip!
I've put up a less verbose version of the patch in accordance with @petrochenkov's advice. |
…richton Right now comparing a `&String` (or a `&Cow`) to a `&str` requires redundant borrowing of the latter. Implementing `PartialEq<str>` tries to avoid this limitation. ```rust struct Foo (String); fn main () { let s = Foo("foo".to_string()); match s { Foo(ref x) if x == &"foo" => println!("foo!"), // avoid this -----^ _ => {} } } ``` I was hoping that rust-lang#23521 would solve this but it didn't work out.
Right now comparing a `&String` (or a `&Cow`) to a `&str` requires redundant borrowing of the latter. Implementing `PartialEq<str>` tries to avoid this limitation. ```rust struct Foo (String); fn main () { let s = Foo("foo".to_string()); match s { Foo(ref x) if x == &"foo" => println!("foo!"), // avoid this -----^ _ => {} } } ``` I was hoping that #23521 would solve this but it didn't work out.
Right now comparing a
&String
(or a&Cow
) to a&str
requires redundant borrowing of the latter. ImplementingPartialEq<str>
tries to avoid this limitation.I was hoping that #23521 would solve this but it didn't work out.