use std::{
fmt,
ops::{Bound, RangeBounds},
};
pub type Interval = (Bound<i32>, Bound<i32>);
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Mapped {
name: String,
start: Bound<i32>,
end: Bound<i32>,
}
impl Mapped {
pub fn new<S, B>(name: S, interval: B) -> Self
where
S: Into<String>,
B: RangeBounds<i32>,
{
Self {
name: name.into(),
start: interval.start_bound().cloned(),
end: interval.end_bound().cloned(),
}
}
pub fn name(&self) -> &str {
&self.name
}
pub fn start(&self) -> Bound<i32> {
self.start
}
pub fn end(&self) -> Bound<i32> {
self.end
}
pub fn interval(&self) -> Interval {
(self.start, self.end)
}
}
impl fmt::Display for Mapped {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.interval() {
(Bound::Unbounded, Bound::Unbounded) => write!(f, "{}", self.name()),
(Bound::Included(s), Bound::Unbounded) => write!(f, "{}:{}", self.name(), s),
(Bound::Included(s), Bound::Included(e)) => write!(f, "{}:{}-{}", self.name(), s, e),
_ => todo!(),
}
}
}