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

PartialEq is not implemented in version 0.2 #313

Closed
tredoe opened this issue Jan 1, 2017 · 4 comments
Closed

PartialEq is not implemented in version 0.2 #313

tredoe opened this issue Jan 1, 2017 · 4 comments

Comments

@tredoe
Copy link

tredoe commented Jan 1, 2017

With the version 0.2, I get:

error[E0369]: binary operation `==` cannot be applied to type `std::option::Option<regex::Regex>`

note: an implementation of `std::cmp::PartialEq` might be missing for `std::option::Option<regex::Regex>`
@BurntSushi
Copy link
Member

Indeed it is not. See the changelog please. :-)

@tredoe
Copy link
Author

tredoe commented Jan 1, 2017

BUG #178: Drop the PartialEq and Eq impls on Regex.

The PartialEq and Eq impls on Regex have been dropped. If you relied on these impls, the fix is to define a wrapper type around Regex, impl Deref on it and provide the necessary impls.

@tredoe
Copy link
Author

tredoe commented Jan 1, 2017

Please, could you add an example about how do it? For beginners
Thanks!

@BurntSushi
Copy link
Member

Oh absolutely! I'm on mobile right now, so it's a a little tough to write it the code, but I'll try to get the idea across and then clean it up later. :-)

The low tech solution is to just change re1 == re2 to re1.as_str() == re2.as_str(). That might be all you need. But if you're, say, using regexes as keys in a btree map, then you'll need a wrapper type that implements PartialEq for you.

First, you need to define a wrapper type: struct MyRegex(regex::Regex). For convenience, you'll want to implement the std::ops::Deref trait. This will make it so you can call all of the methods on Regex through your MyRegex type. Second, you'll need to implement the std::cmp::PartialEq on your MyRegex type, which can be done using the the as_str methods from the "low tech" solution above.

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

No branches or pull requests

2 participants