Initial Commit

This commit is contained in:
2025-08-28 02:26:06 -04:00
committed by Val
commit c83218d750
17 changed files with 2276 additions and 0 deletions

42
src/span.rs Normal file
View File

@@ -0,0 +1,42 @@
use std::ops::Range;
/// Stores the start and end byte position
#[derive(Clone, Copy, Default, PartialEq, Eq)]
pub struct Span {
pub head: u32,
pub tail: u32,
}
impl std::fmt::Debug for Span {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self { head, tail } = self;
write!(f, "[{head}:{tail}]")
}
}
#[allow(non_snake_case)]
/// Stores the start and end byte position
pub fn Span(head: u32, tail: u32) -> Span {
Span { head, tail }
}
impl Span {
/// Updates `self` to include all but the last byte in `other`
pub fn merge(self, other: Span) -> Span {
Span { head: self.head.min(other.head), tail: self.tail.max(other.head) }
}
}
impl From<Span> for Range<usize> {
fn from(value: Span) -> Self {
let Span { head, tail } = value;
(head as usize)..(tail as usize)
}
}
impl std::fmt::Display for Span {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self { head, tail } = self;
write!(f, "{head}:{tail}")
}
}