use crate::Context;
pub type Position = u32;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct Span<'a>(&'a SpanInner<'a>);
#[derive(Debug, Eq, Hash, PartialEq)]
struct SpanInner<'a> {
filename: &'a str,
start: Position,
end: Position,
}
impl<'a> Span<'a> {
pub fn new(
context: &'a Context<'a>,
filename: &'a str,
start: Position,
end: Position,
) -> Self {
let span = Span(context.allocator().alloc(SpanInner {
filename,
start,
end,
}));
context.spans().borrow_mut().insert(span);
span
}
pub const fn filename(&self) -> &'a str {
self.0.filename
}
pub const fn start(&self) -> Position {
self.0.start
}
pub const fn end(&self) -> Position {
self.0.end
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn create() {
let context = Context::new();
Span::new(&context, "foo.rs", 0, 1);
}
}