pub struct MemWordWriterSlice<W: Word, B: AsMut<[W]>> { /* private fields */ }
Expand description
An implementation of WordRead
, WordWrite
, and WordSeek
for a
mutable slice.
Writing beyond the end of the slice will return an error.
§Example
use dsi_bitstream::prelude::*;
let mut words: [u64; 2] = [
0x0043b59fcdf16077,
0x702863e6f9739b86,
];
let mut word_writer = MemWordWriterSlice::new(&mut words);
// the stream is read sequentially
assert_eq!(word_writer.word_pos()?, 0);
assert_eq!(word_writer.read_word()?, 0x0043b59fcdf16077);
assert_eq!(word_writer.word_pos()?, 1);
assert_eq!(word_writer.read_word()?, 0x702863e6f9739b86);
assert_eq!(word_writer.word_pos()?, 2);
assert!(word_writer.read_word().is_err());
// you can change position
assert!(word_writer.set_word_pos(1).is_ok());
assert_eq!(word_writer.word_pos()?, 1);
assert_eq!(word_writer.read_word()?, 0x702863e6f9739b86);
// errored set position doesn't change the current position
assert_eq!(word_writer.word_pos()?, 2);
assert!(word_writer.set_word_pos(100).is_err());
assert_eq!(word_writer.word_pos()?, 2);
// we can write and read back!
assert!(word_writer.set_word_pos(0).is_ok());
assert!(word_writer.write_word(0x0b801b2bf696e8d2).is_ok());
assert_eq!(word_writer.word_pos()?, 1);
assert!(word_writer.set_word_pos(0).is_ok());
assert_eq!(word_writer.read_word()?, 0x0b801b2bf696e8d2);
assert_eq!(word_writer.word_pos()?, 1);
Implementations§
Trait Implementations§
Source§impl<W: Word, B> CopyType for MemWordWriterSlice<W, B>
impl<W: Word, B> CopyType for MemWordWriterSlice<W, B>
Source§impl<W: Word, B> MemDbgImpl for MemWordWriterSlice<W, B>
impl<W: Word, B> MemDbgImpl for MemWordWriterSlice<W, B>
fn _mem_dbg_rec_on( &self, _memdbg_writer: &mut impl Write, _memdbg_total_size: usize, _memdbg_max_depth: usize, _memdbg_prefix: &mut String, _memdbg_is_last: bool, _memdbg_flags: DbgFlags, ) -> Result
fn _mem_dbg_depth_on( &self, writer: &mut impl Write, total_size: usize, max_depth: usize, prefix: &mut String, field_name: Option<&str>, is_last: bool, padded_size: usize, flags: DbgFlags, ) -> Result<(), Error>
Source§impl<W: Word, B> MemSize for MemWordWriterSlice<W, B>
impl<W: Word, B> MemSize for MemWordWriterSlice<W, B>
impl<W: Word, B: AsMut<[W]>> StructuralPartialEq for MemWordWriterSlice<W, B>
Auto Trait Implementations§
impl<W, B> Freeze for MemWordWriterSlice<W, B>where
B: Freeze,
impl<W, B> RefUnwindSafe for MemWordWriterSlice<W, B>where
B: RefUnwindSafe,
W: RefUnwindSafe,
impl<W, B> Send for MemWordWriterSlice<W, B>where
B: Send,
impl<W, B> Sync for MemWordWriterSlice<W, B>where
B: Sync,
impl<W, B> Unpin for MemWordWriterSlice<W, B>
impl<W, B> UnwindSafe for MemWordWriterSlice<W, B>where
B: UnwindSafe,
W: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
impl<T, U> CastableInto<U> for Twhere
U: CastableFrom<T>,
Source§impl<T> DowncastableFrom<T> for T
impl<T> DowncastableFrom<T> for T
Source§fn downcast_from(value: T) -> T
fn downcast_from(value: T) -> T
Truncate the current UnsignedInt to a possibly smaller size
Source§impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
impl<T, U> DowncastableInto<U> for Twhere
U: DowncastableFrom<T>,
Source§impl<T> MemDbg for Twhere
T: MemDbgImpl,
impl<T> MemDbg for Twhere
T: MemDbgImpl,
Source§fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>
fn mem_dbg(&self, flags: DbgFlags) -> Result<(), Error>
Writes to stderr debug infos about the structure memory usage, expanding
all levels of nested structures.
Source§fn mem_dbg_on(
&self,
writer: &mut impl Write,
flags: DbgFlags,
) -> Result<(), Error>
fn mem_dbg_on( &self, writer: &mut impl Write, flags: DbgFlags, ) -> Result<(), Error>
Writes to a
core::fmt::Write
debug infos about the structure memory
usage, expanding all levels of nested structures.Source§fn mem_dbg_depth(&self, max_depth: usize, flags: DbgFlags) -> Result<(), Error>
fn mem_dbg_depth(&self, max_depth: usize, flags: DbgFlags) -> Result<(), Error>
Writes to stderr debug infos about the structure memory usage as
mem_dbg
, but expanding only up to max_depth
levels of nested structures.Source§fn mem_dbg_depth_on(
&self,
writer: &mut impl Write,
max_depth: usize,
flags: DbgFlags,
) -> Result<(), Error>
fn mem_dbg_depth_on( &self, writer: &mut impl Write, max_depth: usize, flags: DbgFlags, ) -> Result<(), Error>
Writes to a
core::fmt::Write
debug infos about the structure memory
usage as mem_dbg_on
, but expanding only up to
max_depth
levels of nested structures.Source§impl<T> UpcastableFrom<T> for T
impl<T> UpcastableFrom<T> for T
Source§fn upcast_from(value: T) -> T
fn upcast_from(value: T) -> T
Extend the current UnsignedInt to a possibly bigger size.