pub trait Range {
fn start(&self) -> usize;
fn end(&self) -> Option<usize>;
}
impl Range for std::ops::Range<usize> {
fn start(&self) -> usize {
self.start
}
fn end(&self) -> Option<usize> {
Some(self.end)
}
}
impl Range for std::ops::RangeFrom<usize> {
fn start(&self) -> usize {
self.start
}
fn end(&self) -> Option<usize> {
None
}
}
impl Range for std::ops::RangeTo<usize> {
fn start(&self) -> usize {
0
}
fn end(&self) -> Option<usize> {
Some(self.end)
}
}
impl Range for std::ops::RangeFull {
fn start(&self) -> usize {
0
}
fn end(&self) -> Option<usize> {
None
}
}
impl Range for std::ops::RangeInclusive<usize> {
fn start(&self) -> usize {
*self.start()
}
fn end(&self) -> Option<usize> {
Some(*self.end() + 1)
}
}
impl Range for std::ops::RangeToInclusive<usize> {
fn start(&self) -> usize {
0
}
fn end(&self) -> Option<usize> {
Some(self.end + 1)
}
}