use crate::{SourceMap, SourceSpan};
#[derive(Copy, Clone, Debug, Default, Eq, Hash, PartialEq)]
#[repr(C)]
pub struct ByteSpan {
pub start: u32,
pub end: u32,
}
impl ByteSpan {
#[inline]
pub fn new(start: u32, end: u32) -> Self {
debug_assert!(
start <= end,
"ByteSpan::new called with start ({start}) > end ({end})",
);
Self { start, end }
}
#[inline]
pub fn len(&self) -> u32 {
self.end - self.start
}
#[inline]
pub fn is_empty(&self) -> bool {
self.start == self.end
}
#[inline]
pub fn empty_at(offset: u32) -> Self {
Self {
start: offset,
end: offset,
}
}
#[inline]
pub fn merge(self, other: ByteSpan) -> ByteSpan {
ByteSpan {
start: self.start.min(other.start),
end: self.end.max(other.end),
}
}
#[inline]
pub fn resolve(&self, source_map: &SourceMap) -> Option<SourceSpan> {
source_map.resolve_span(*self)
}
}