Add Located::start, Located::end and impl Deref

This commit is contained in:
Micha Reiser 2023-04-26 10:24:34 -06:00
parent 3873414b30
commit ae9d3c3193
4 changed files with 65 additions and 36 deletions

View file

@ -24,6 +24,24 @@ impl<T> Located<T> {
node,
}
}
pub const fn start(&self) -> Location {
self.location
}
/// Returns the node's [`end_location`](Located::end_location) or [`location`](Located::start) if
/// [`end_location`](Located::end_location) is `None`.
pub fn end(&self) -> Location {
self.end_location.unwrap_or(self.location)
}
}
impl<T, U> std::ops::Deref for Located<T, U> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.node
}
}
#[derive(Clone, Debug, PartialEq)]