Buffer

Struct Buffer 

Source
pub struct Buffer<T>
where T: AsMut<[u8]> + AsRef<[u8]>,
{ /* private fields */ }

Implementations§

Source§

impl<T> Buffer<T>
where T: AsMut<[u8]> + AsRef<[u8]>,

Source

pub fn new(source: T) -> Buffer<T>

Create a new buffer from any source

§Example
    use buffer::Buffer;
 
    let mut bytes = [0; 1024];
    let mut buffer = Buffer::new(&mut bytes);
Source

pub fn reset(&mut self)

Reset the buffer to its initial state

Source

pub fn capacity(&self) -> usize

Returns the length of the undelying buffer

Source

pub fn remaining_capacity(&self) -> usize

Returns the remaining space that can be written This method does not perform a Buffer::shift

Source

pub fn has_remaining_capacity(&self) -> bool

returns if there is remaining is equal to Buffer::remaining_capacity() > 0

Source

pub fn remaining_len(&self) -> usize

Returns the remaining bayes to read

Source

pub fn has_remaining_len(&self) -> bool

Source

pub fn has_dead_capacity(&self) -> bool

Returns true if the read position is > 0

Source

pub fn shift(&mut self)

Shifts the content of the source left to reuse space of read bytes.

Source

pub fn ensure_remaining_capacity(&mut self) -> bool

Performa s Buffer::shift if there is no remianing capacity and returns if there is remainig capacity afterwards

Source

pub fn create_reader_with_max(&mut self, max_bytes: usize) -> Reader<'_, T>

Source

pub fn data(&self) -> &[u8]

Returns a slice containing the readable data

Source

pub fn skip(&mut self, n: usize) -> Result<(), BufferError>

Skips n readable bytes

§Errors

BufferError::NoData if n < self.remaining_len()

Source

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

Appends the provided slice to the buffer a a whole

§Error

BufferError::NoCapacity if buf.len() > self.remaining_capacity()

Trait Implementations§

Source§

impl<T> Clone for Buffer<T>
where T: AsMut<[u8]> + AsRef<[u8]> + Clone,

Source§

fn clone(&self) -> Buffer<T>

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<T> Debug for Buffer<T>
where T: Debug + AsMut<[u8]> + AsRef<[u8]>,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> ErrorType for Buffer<T>
where T: AsMut<[u8]> + AsRef<[u8]>,

Source§

type Error = ErrorKind

Error type of all the IO operations on this type.
Source§

impl<T> Read for Buffer<T>
where T: AsMut<[u8]> + AsRef<[u8]>,

Source§

fn read( &mut self, buf: &mut [u8], ) -> Result<usize, <Buffer<T> as ErrorType>::Error>

Read some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Source§

fn read_exact( &mut self, buf: &mut [u8], ) -> Result<(), ReadExactError<Self::Error>>

Read the exact number of bytes required to fill buf. Read more
Source§

impl<T> ReadWrite for Buffer<T>
where T: AsMut<[u8]> + AsRef<[u8]>,

Source§

fn create_reader<'a>(&'a mut self) -> impl BufferReader + 'a

Source§

fn create_writer<'a>(&'a mut self) -> impl BufferWriter + 'a

Source§

impl<T> Write for Buffer<T>
where T: AsMut<[u8]> + AsRef<[u8]>,

Source§

fn write( &mut self, buf: &[u8], ) -> Result<usize, <Buffer<T> as ErrorType>::Error>

Write a buffer into this writer, returning how many bytes were written. Read more
Source§

fn flush(&mut self) -> Result<(), <Buffer<T> as ErrorType>::Error>

Flush this output stream, blocking until all intermediately buffered contents reach their destination.
Source§

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

Write an entire buffer into this writer. Read more
Source§

fn write_fmt( &mut self, fmt: Arguments<'_>, ) -> Result<(), WriteFmtError<Self::Error>>

Write a formatted string into this writer, returning any error encountered. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Buffer<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Buffer<T>
where T: RefUnwindSafe,

§

impl<T> Send for Buffer<T>
where T: Send,

§

impl<T> Sync for Buffer<T>
where T: Sync,

§

impl<T> Unpin for Buffer<T>
where T: Unpin,

§

impl<T> UnwindSafe for Buffer<T>
where T: UnwindSafe,

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.