smb_dtyp/binrw_util/
debug.rs

1#![cfg(debug_assertions)]
2//! This module contains a debug utility for logging read/write positions in binrw operations.
3
4use binrw::prelude::*;
5
6/// Prints the current stream position for debugging purposes.
7#[derive(Debug, Default, PartialEq, Eq)]
8pub struct LogLocation {}
9
10impl BinRead for LogLocation {
11    type Args<'a> = ();
12    fn read_options<R: std::io::Read + std::io::Seek>(
13        reader: &mut R,
14        _endian: binrw::Endian,
15        _args: Self::Args<'_>,
16    ) -> BinResult<Self> {
17        dbg!(("Reading log location is: ", reader.stream_position()?));
18        Ok(LogLocation {})
19    }
20}
21impl BinWrite for LogLocation {
22    type Args<'a> = ();
23    fn write_options<W: std::io::Write + std::io::Seek>(
24        &self,
25        writer: &mut W,
26        _endian: binrw::Endian,
27        _args: Self::Args<'_>,
28    ) -> BinResult<()> {
29        dbg!(("Writing log location is: ", writer.stream_position()?));
30        Ok(())
31    }
32}