1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use std::{cmp::Ordering, ops::Bound};

pub trait CompareBounds<T: PartialOrd<T>> {
    fn cmp_bounds(&self, b: Bound<T>) -> Option<Ordering>;
}

impl<T: PartialOrd<T>> CompareBounds<T> for Bound<T> {
    fn cmp_bounds(&self, b: Bound<T>) -> Option<Ordering> {
        match (self, b) {
            (Bound::Unbounded, Bound::Unbounded) => Some(Ordering::Equal),
            (Bound::Included(lower), Bound::Included(upper))
            | (Bound::Excluded(lower), Bound::Included(upper))
            | (Bound::Included(lower), Bound::Excluded(upper))
            | (Bound::Excluded(lower), Bound::Excluded(upper)) => lower.partial_cmp(&upper),
            _ => None,
        }
    }
}