use serde::{Deserialize, Serialize};
use std::sync::Arc;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize, PartialOrd, Ord)]
pub struct Loc {
pub span: miette::SourceSpan,
pub src: Arc<str>,
}
impl Loc {
pub fn new(span: impl Into<miette::SourceSpan>, src: Arc<str>) -> Self {
Self {
span: span.into(),
src,
}
}
pub fn span(&self, span: impl Into<miette::SourceSpan>) -> Self {
Self {
span: span.into(),
src: Arc::clone(&self.src),
}
}
pub fn start(&self) -> usize {
self.span.offset()
}
pub fn end(&self) -> usize {
self.span.offset() + self.span.len()
}
pub fn snippet(&self) -> Option<&str> {
self.src.get(self.start()..self.end())
}
}