use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SeekError(pub usize);
impl fmt::Display for SeekError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(self, f)
}
}
impl std::error::Error for SeekError {}
pub trait BytesSeek {
fn position(&self) -> usize;
fn try_seek(&mut self, pos: usize) -> Result<(), SeekError>;
#[track_caller]
fn seek(&mut self, pos: usize) {
self.try_seek(pos).expect("failed to seek");
}
fn try_advance(&mut self, adv: usize) -> Result<(), SeekError> {
self.try_seek(self.position() + adv)
}
#[track_caller]
fn advance(&mut self, adv: usize) {
self.try_advance(adv).expect("failed to advance")
}
}