-
Notifications
You must be signed in to change notification settings - Fork 2
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
Support RangeBounds
for T: Comparable
#4
base: master
Are you sure you want to change the base?
Conversation
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.
I think having a separate trait will make this awkward to use, because that's an additional constraint on the range type that you'd have to propagate in API. How about something like this added to Comparable
(with a default impl):
fn compare_contains<R: RangeBounds<Self>>(range: R, key: &K) -> bool;
It will be more awkward to use without the self
receiver though, so I'm not sure this is better -- just an alternative to consider.
This would also keep the "direction" consistent, like my other comment.
src/lib.rs
Outdated
/// ``` | ||
fn comparable_contains<U>(&self, item: &U) -> bool | ||
where | ||
U: ?Sized + Comparable<T>, |
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.
What is the intended use case? If it's something like BTreeMap::range
, then I think the relationship should be the other way, T: Comparable<U>
, or in map terms it's RangeBounds<Q>
and Q: Comparable<K>
.
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.
The intended use case is most like a BTreeMap
, I need something like
fn foo<R, Q>(&self, key: &K)
where
R: RangeBounds<Q>,
Q: ?Sized + Comparable<K>
{
if self.range.comparable_contains(key) { }
}
Yeah, another trait will require users to import it, but if there is no |
Hmm, my thought was more that you would have to add the trait as a constraint in your public API, but I guess that's not true -- with the blanket impl, you can still use it as long as
Yes, or I'd write |
Hi, this PR adds functionality like
RangeBounds::contains
forT: Comparable
.