use std::io::{Seek, SeekFrom};
use std::panic::Location;
use crate::{Error, Result};
pub trait Seeker {
#[track_caller]
fn goto(&mut self, pos: u64) -> Result<u64> { self.goto_tracked(pos, Location::caller()) }
fn goto_tracked(&mut self, pos: u64, caller: &'static Location) -> Result<u64>;
#[track_caller]
fn position(&mut self) -> Result<u64> { self.position_tracked(Location::caller()) }
fn position_tracked(&mut self, caller: &'static Location) -> Result<u64>;
}
impl<Base> Seeker for Base
where
Base: Seek + Sized,
{
#[inline]
fn goto_tracked(&mut self, pos: u64, caller: &'static Location) -> Result<u64> {
match self.seek(SeekFrom::Start(pos)) {
Ok(_) => Ok(pos),
Err(e) => Err(Error::SeekFailed(e, caller)),
}
}
#[inline]
fn position_tracked(&mut self, caller: &'static Location) -> Result<u64> {
match self.stream_position() {
Ok(pos) => Ok(pos),
Err(e) => Err(Error::SeekFailed(e, caller)),
}
}
}