#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(transparent)]
pub struct TextSpan(pub TextSource);
impl TextSpan {
pub(crate) const fn new_static(s: &'static str) -> Self {
Self(TextSource::StaticText(s))
}
pub(crate) fn new(start: u32, len: u32) -> Self {
Self(TextSource::Text(Span { start, len }))
}
pub(crate) fn new_span(span: Span) -> Self {
Self(TextSource::Text(span))
}
pub(crate) fn offset(&self, delta: u32) -> TextSpan {
match self.0 {
TextSource::Text(span) => TextSpan::new_span(span.offset(delta)),
_ => *self,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TextSource {
StaticText(&'static str),
Text(Span),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Span {
pub start: u32,
pub len: u32,
}
impl Span {
pub const fn new(start: u32, len: u32) -> Self {
Self { start, len }
}
pub(crate) fn offset(&self, delta: u32) -> Span {
Span {
start: self.start + delta,
len: self.len,
}
}
}