use core::{fmt, str};
#[derive(Clone, Copy, Debug)]
pub struct Span {
pub offset: usize,
pub len: usize,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct FilePosition {
pub start_line: usize,
pub start_col: usize,
pub end_line: usize,
pub end_col: usize,
}
impl fmt::Display for FilePosition {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let FilePosition {
start_line,
start_col,
end_line,
end_col,
} = self;
write!(f, "[{start_line}:{start_col},{end_line}:{end_col}]")
}
}
impl Span {
#[must_use]
#[inline]
pub fn slice<'a>(&self, src: &'a str) -> &'a str {
&src[self.offset..self.offset + self.len]
}
}
impl fmt::Display for Span {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "[{}:{}]", self.offset, self.offset + self.len)
}
}