40 lines
794 B
Rust
40 lines
794 B
Rust
use crate::FileId;
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
|
|
pub struct Span {
|
|
pub file: FileId,
|
|
pub start: u32, // byte offset
|
|
pub end: u32, // byte offset, exclusive
|
|
}
|
|
|
|
impl Span {
|
|
#[inline]
|
|
pub fn new(file: FileId, start: u32, end: u32) -> Self {
|
|
Self { file, start, end }
|
|
}
|
|
|
|
#[inline]
|
|
pub fn none() -> Self {
|
|
Self {
|
|
file: FileId::NONE,
|
|
start: 0,
|
|
end: 0,
|
|
}
|
|
}
|
|
|
|
#[inline]
|
|
pub fn is_none(&self) -> bool {
|
|
self.file.is_none()
|
|
}
|
|
|
|
#[inline]
|
|
pub fn len(&self) -> u32 {
|
|
self.end.saturating_sub(self.start)
|
|
}
|
|
|
|
#[inline]
|
|
pub fn contains(&self, byte: u32) -> bool {
|
|
self.start <= byte && byte < self.end
|
|
}
|
|
}
|