pub mod reader;
pub mod writer;
pub use reader::*;
pub use writer::*;
pub fn measure<S, T, E>(
seekable: &mut S,
mut inner: impl FnMut(&mut S) -> Result<T, E>,
) -> Result<(u64, T), E>
where
S: std::io::Seek + ?Sized,
E: std::error::Error + From<std::io::Error>,
{
let start = seekable.stream_position()?;
let val = inner(seekable)?;
Ok((seekable.stream_position()?.saturating_sub(start), val))
}
pub fn window_at<S, T, E>(
seekable: &mut S,
at: u64,
mut inner: impl FnMut(&mut S) -> Result<T, E>,
) -> Result<T, E>
where
S: std::io::Seek + ?Sized,
E: std::error::Error + From<std::io::Error>,
{
let original = seekable.stream_position()?;
seekable.seek(std::io::SeekFrom::Start(at))?;
let val = inner(seekable)?;
seekable.seek(std::io::SeekFrom::Start(original))?;
Ok(val)
}
pub fn window<S, T, E>(
seekable: &mut S,
mut inner: impl FnMut(&mut S) -> Result<T, E>,
) -> Result<T, E>
where
S: std::io::Seek + ?Sized,
E: std::error::Error + From<std::io::Error>,
{
let original = seekable.stream_position()?;
let val = inner(seekable)?;
seekable.seek(std::io::SeekFrom::Start(original))?;
Ok(val)
}