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 for value inside activevalue #1614
base: master
Are you sure you want to change the base?
partialEq for value inside activevalue #1614
Conversation
Just wanted to inform that // This will work
assert!(ActiveValue::Set(2) == 2);
// This will give compilation error
assert!(2 == ActiveValue::Set(2)); |
I think this is the best we can get: assert!(ActiveValue::Set(2) == 2); We wouldn't be able to make this works: assert!(2 == ActiveValue::Set(2)); Because we simply can't implement |
However, I think we can provide an |
This will make sure that we are only comparing with If i am right then user has to convert data to ActiveValue::Set(2) == Value::from(2)
// or may be this
ActiveValue::Set(2) == 2.into_value() |
I mean comparing assert!(ActiveValue::Set(2) == Value::from(2));
assert!(ActiveValue::Unchanged(String::from("hi")) == Value::from("hi")); However, after second thought, it'd be more intuitive to do... instead assert!(ActiveValue::Set(2) == 2);
assert!(ActiveValue::Unchanged(String::from("hi")) == "hi"); |
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!! @Diwakar-Gupta
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.
Hey @Diwakar-Gupta, after second thought... I think comparing ActiveValue<V>
with Option<V>
make more sense. This way we don't leave out ActiveValue::NotSet
.
753d1cb
to
ad5c317
Compare
7dadae9
to
c02364c
Compare
I still feel like below has a little too much type magic: assert!(ActiveValue::Set(2) == Some(2)); Actually, the solution can be much simpler: we only have to add a method: fn as_ref(&self) -> Option<&V> Such that we can: assert!(ActiveValue::Set(2).as_ref() == Some(2).as_ref()); this will work right? |
based on the requirement from issue this will work. Never thought it can be solved with this simplicity. |
Can we give thought to possible solution once again below only utilizes Set and Unchanged only but client api is very simple assert!(ActiveValue::Set(2) == 2); this utilizes Set and Unchanged and NotSet assert!(ActiveValue::Set(2) == Some(2)); and the third one which get's converetd to Option<> assert!(ActiveValue::Set(2).as_ref() == Some(2).as_ref()); |
PR Info
Closes Add contains method for ActiveValue #1533
Dependencies:
No Dependencies
Dependents:
No Dependents
New Features
Breaking Changes
Changes
impl<U, V> PartialEq<U> for ActiveValue<V>