Skip to content
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

Merged
merged 2 commits into from
Apr 4, 2015
Merged

Implement PartialEq<str> for String and Cow #23972

merged 2 commits into from
Apr 4, 2015

Conversation

gkoz
Copy link
Contributor

@gkoz gkoz commented Apr 2, 2015

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.

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.

@rust-highfive
Copy link
Collaborator

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 }
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tip!

@gkoz
Copy link
Contributor Author

gkoz commented Apr 2, 2015

I've put up a less verbose version of the patch in accordance with @petrochenkov's advice.

@alexcrichton
Copy link
Member

@bors: r+ 5234063

Thanks!

Manishearth added a commit to Manishearth/rust that referenced this pull request Apr 3, 2015
…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.
bors added a commit that referenced this pull request Apr 3, 2015
@bors
Copy link
Contributor

bors commented Apr 3, 2015

⌛ Testing commit 5234063 with merge f207ecb...

bors added a commit that referenced this pull request Apr 3, 2015
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.
@bors bors merged commit 5234063 into rust-lang:master Apr 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants