Struct dsi_bitstream::impls::MemWordWriterSlice
source · 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.get_word_pos().unwrap(), 0);
assert_eq!(word_writer.read_word().unwrap(), 0x0043b59fcdf16077);
assert_eq!(word_writer.get_word_pos().unwrap(), 1);
assert_eq!(word_writer.read_word().unwrap(), 0x702863e6f9739b86);
assert_eq!(word_writer.get_word_pos().unwrap(), 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.get_word_pos().unwrap(), 1);
assert_eq!(word_writer.read_word().unwrap(), 0x702863e6f9739b86);
// errored set position doesn't change the current position
assert_eq!(word_writer.get_word_pos().unwrap(), 2);
assert!(word_writer.set_word_pos(100).is_err());
assert_eq!(word_writer.get_word_pos().unwrap(), 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.get_word_pos().unwrap(), 1);
assert!(word_writer.set_word_pos(0).is_ok());
assert_eq!(word_writer.read_word().unwrap(), 0x0b801b2bf696e8d2);
assert_eq!(word_writer.get_word_pos().unwrap(), 1);
Implementations§
Trait Implementations§
source§impl<W: PartialEq + Word, B: PartialEq + AsMut<[W]>> PartialEq for MemWordWriterSlice<W, B>
impl<W: PartialEq + Word, B: PartialEq + AsMut<[W]>> PartialEq for MemWordWriterSlice<W, B>
source§fn eq(&self, other: &MemWordWriterSlice<W, B>) -> bool
fn eq(&self, other: &MemWordWriterSlice<W, B>) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl<W: Word, B: AsMut<[W]>> StructuralPartialEq for MemWordWriterSlice<W, B>
Auto Trait Implementations§
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> 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.