use std::ops::Index;
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct Span {
pub start: usize,
pub len: usize,
}
impl Span {
pub const fn new(start: usize, len: usize) -> Self {
Self { start, len }
}
pub const fn end(self) -> usize {
self.start + self.len
}
pub const fn with_offset(self, delta: usize) -> Self {
Span::new(self.start + delta, self.len)
}
}
impl Index<Span> for [u8] {
type Output = [u8];
#[track_caller]
fn index(&self, index: Span) -> &Self::Output {
&self[index.start..index.end()]
}
}