use std::cmp::{max, min};
pub enum NeverType {}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub struct Location(pub usize, pub usize);
impl Location {
pub fn is_empty(self) -> bool {
self.0 == self.1
}
pub fn intersect(self, other: Self) -> Option<Self> {
let begin = max(self.0, other.0);
let end = min(self.1, other.1);
if !self.is_empty() && !other.is_empty() {
if begin < end {
Some(Location(begin, end))
} else {
None
}
} else {
debug_assert!(self.is_empty() || other.is_empty());
if begin <= end {
Some(Location(begin, end))
} else {
None
}
}
}
}