pub struct ByteCursor { /* private fields */ }
Implementations§
Source§impl ByteCursor
impl ByteCursor
Sourcepub const fn new(inner: Vec<u8>) -> Self
pub const fn new(inner: Vec<u8>) -> Self
Creates a new Bytecursor
from the inner bytes it will contains.
Sets the position to 0 initially.
Sourcepub fn into_inner(self) -> Vec<u8>
pub fn into_inner(self) -> Vec<u8>
Consumes the Bytecursor
, returning the inner bytes.
Sourcepub const fn get_ref(&self) -> &Vec<u8>
pub const fn get_ref(&self) -> &Vec<u8>
Returns an immutable reference to the inner bytes of the Bytecursor
Sourcepub fn get_mut(&mut self) -> &mut Vec<u8>
pub fn get_mut(&mut self) -> &mut Vec<u8>
Returns a mutable reference to the inner bytes of the Bytecursor
Sourcepub fn set_position(&mut self, pos: u64)
pub fn set_position(&mut self, pos: u64)
Sets the position of the Bytecursor
to pos
Sourcepub fn read(&mut self, buf: &mut [u8]) -> usize
pub fn read(&mut self, buf: &mut [u8]) -> usize
Reads buf.len()
bytes into buf
from read
, advancing
the Bytecursor
’s position. It returns the number of bytes
actually read.
Sourcepub fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), String>
pub fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), String>
Reads exactly buf.len()
bytes into buf
, throwing an error if
that number of bytes was not able to be read.
§Errors
Will return Err
if the buffer is longer than the available bytes to read
Sourcepub fn fill_buf(&mut self) -> &[u8]
pub fn fill_buf(&mut self) -> &[u8]
Returns a byte slice containing all remaining bytes
in the inner bytes after the current position of the
Bytecursor
.
Sourcepub fn seek(&mut self, style: &SeekFrom) -> Result<u64, String>
pub fn seek(&mut self, style: &SeekFrom) -> Result<u64, String>
Seeks to the position referenced by style
, returning the new position
of the Bytecursor
and throwing an error if the new position would be
invalid. # Errors
Will return Err
if one tries to seek to a negative or overflowing
position
Sourcepub fn write(&mut self, buf: &[u8]) -> Result<usize, String>
pub fn write(&mut self, buf: &[u8]) -> Result<usize, String>
Writes buf.len()
bytes into buf
. Returns the number of bytes actually
read if successful, and throws an error if there aren’t enough bytes to
read. # Errors
Will return Err
if the cursor position exceeds maximum possible vector
length
Trait Implementations§
Source§impl Clone for ByteCursor
impl Clone for ByteCursor
Source§fn clone(&self) -> ByteCursor
fn clone(&self) -> ByteCursor
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more