Struct ByteCursor

Source
pub struct ByteCursor { /* private fields */ }

Implementations§

Source§

impl ByteCursor

Source

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.

Source

pub fn into_inner(self) -> Vec<u8>

Consumes the Bytecursor, returning the inner bytes.

Source

pub const fn get_ref(&self) -> &Vec<u8>

Returns an immutable reference to the inner bytes of the Bytecursor

Source

pub fn get_mut(&mut self) -> &mut Vec<u8>

Returns a mutable reference to the inner bytes of the Bytecursor

Source

pub const fn position(&self) -> u64

Returns the current position of the Bytecursor

Source

pub fn set_position(&mut self, pos: u64)

Sets the position of the Bytecursor to pos

Source

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.

Source

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

Source

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.

Source

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

Source

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

Source

pub fn write_all(&mut self, buf: &[u8]) -> Result<(), String>

Writes all of buf to the Bytecursor until buf is empty.

§Errors

Will return Err if the cursor position exceeds maximum possible vector length or we failed to write whole buffer

Trait Implementations§

Source§

impl Clone for ByteCursor

Source§

fn clone(&self) -> ByteCursor

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ByteCursor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.