#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct ByteRange {
start: usize,
end: usize,
}
impl ByteRange {
#[must_use]
pub const fn new(start: usize, end: usize) -> Self {
assert!(start <= end, "byte range start must not exceed end");
Self { start, end }
}
#[must_use]
pub const fn start(self) -> usize {
self.start
}
#[must_use]
pub const fn end(self) -> usize {
self.end
}
#[must_use]
pub const fn intersects(self, other: Self) -> bool {
if self.start == self.end || other.start == other.end {
self.start <= other.end && other.start <= self.end
} else {
self.start < other.end && other.start < self.end
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Point {
row: usize,
column: usize,
}
impl Point {
#[must_use]
pub const fn new(row: usize, column: usize) -> Self {
Self { row, column }
}
#[must_use]
pub const fn row(self) -> usize {
self.row
}
#[must_use]
pub const fn column(self) -> usize {
self.column
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct SourceSpan {
byte_range: ByteRange,
start_point: Point,
end_point: Point,
}
impl SourceSpan {
#[must_use]
pub const fn new(byte_range: ByteRange, start_point: Point, end_point: Point) -> Self {
Self {
byte_range,
start_point,
end_point,
}
}
#[must_use]
pub const fn byte_range(self) -> ByteRange {
self.byte_range
}
#[must_use]
pub const fn start_point(self) -> Point {
self.start_point
}
#[must_use]
pub const fn end_point(self) -> Point {
self.end_point
}
}