#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Span { pub start: usize, pub end: usize, } impl Span { pub fn new(start: usize, end: usize) -> Self { Self { start, end } } pub fn len(&self) -> usize { self.end - self.start } pub fn is_empty(&self) -> bool { self.start == self.end } pub fn merge(&self, other: &Span) -> Span { Span { start: self.start.min(other.start), end: self.end.max(other.end), } } } pub trait Spanned { fn span(&self) -> Span; }