use crate::{
io::{Read, Seek},
BinRead, BinResult, Endian,
};
use core::fmt;
pub struct PosValue<T> {
pub val: T,
pub pos: u64,
}
impl<T: BinRead> BinRead for PosValue<T> {
type Args<'a> = T::Args<'a>;
fn read_options<R: Read + Seek>(
reader: &mut R,
endian: Endian,
args: Self::Args<'_>,
) -> BinResult<Self> {
let pos = reader.stream_position()?;
Ok(PosValue {
pos,
val: T::read_options(reader, endian, args)?,
})
}
}
impl<T> core::ops::Deref for PosValue<T> {
type Target = T;
fn deref(&self) -> &T {
&self.val
}
}
impl<T> core::ops::DerefMut for PosValue<T> {
fn deref_mut(&mut self) -> &mut T {
&mut self.val
}
}
impl<T: fmt::Debug> fmt::Debug for PosValue<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.val.fmt(f)
}
}
impl<T: Clone> Clone for PosValue<T> {
fn clone(&self) -> Self {
Self {
val: self.val.clone(),
pos: self.pos,
}
}
}
impl<U, T: PartialEq<U>> PartialEq<U> for PosValue<T> {
fn eq(&self, other: &U) -> bool {
self.val == *other
}
}