use serde::{Deserialize, Serialize};
use std::sync::Arc;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Span {
pub file: Arc<String>,
pub start: usize,
pub end: usize,
pub line: u32,
pub col: u32,
}
impl Span {
pub fn new(file: Arc<String>, start: usize, end: usize, line: u32, col: u32) -> Self {
Self {
file,
start,
end,
line,
col,
}
}
pub fn len(&self) -> usize {
self.end.saturating_sub(self.start)
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
}
impl From<&Span> for miette::SourceSpan {
fn from(span: &Span) -> Self {
miette::SourceSpan::new(miette::SourceOffset::from(span.start), span.len())
}
}
impl From<Span> for miette::SourceSpan {
fn from(span: Span) -> Self {
(&span).into()
}
}