RangeBounds today is a standard trait to represent ranges and provides a single method contains
used to determine if a range contains a given element.
Another common operation on ranges (like intervals) is to check if 2 overlap. Today there is no method to check for that
pub trait RangeBounds<T: ?Sized> {
/// Returns `true` if there exists an element present in both ranges.
///
/// # Examples
///
/// ```
/// assert!( (3..5).overlaps(&(1..4));
/// assert!(!(3..5).overlaps(&(5..6));
/// ```
///
fn overlaps<O, E>(&self, other: &O) -> bool
where
T: PartialOrd<E>,
E: ?Sized + PartialOrd<T>,
O: RangeBounds<E>,
{
todo!()
}
}
Open questions
There is a question whether to consider (Excluded(1), Excluded(3)) as overlapping with (Excluded(2), Excluded(5)).
Since this is only a problem for cases where a discrete step between elements is known we could have a specialized implementation for anything that implements Step
that handles these cases.
Alternative would be for developers to implement it on specific types, or an extension trait on top of RangeBounds (which could be a separate crate)
Links and related workRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4