UnownedWriteBuffer

Struct UnownedWriteBuffer 

Source
pub struct UnownedWriteBuffer<const S: usize> { /* private fields */ }
Expand description

Unowned Write buffer.

§S Generic: Size of the buffer.

beware that if this size is too large, and you stack allocate this struct then you will hit the guard page and your program will crash. If you must use very large buffers then Box this struct.

Implementations§

Source§

impl<const S: usize> UnownedWriteBuffer<S>

Source

pub const fn new() -> Self

Construct a new Buffer

§Panics

if S is smaller than 16.

Source§

impl<const S: usize> UnownedWriteBuffer<S>

Source

pub const fn available(&self) -> usize

Returns the amount of bytes that can still be written into the internal buffer.

Source

pub const fn size(&self) -> usize

Source

pub fn flush<T: Write>(&mut self, write: &mut T) -> Result<()>

Flush all bytes to the underlying Write impl. This call also calls Write::flush afterward.

§Errors

Propagated from Write impl

Source

pub fn try_write<T: Write>(&mut self, buffer: &[u8]) -> usize

Write as many bytes as can still fit to the internal buffer. This function returns 0 if the internal buffer is full. If the supplied buffer is only partially written then this fn guarantees that the entire internal buffer has been filled and subsequent calls to try_write are pointless unless flush or write/write_all are first called.

Source

pub fn write<T: Write>(&mut self, write: &mut T, buffer: &[u8]) -> Result<usize>

Write as many bytes as can still fit to the internal buffer. This call will not push the internal buffer to the Write impl if the internal buffer still had room for at least one byte. It is only guaranteed to at least “write” 1 byte. This fn might call the underlying write impl several times.

§Errors

Propagated from Write impl

Source

pub fn write_all<T: Write>( &mut self, write: &mut T, buffer: &[u8], ) -> Result<()>

Writes all bytes to the internal buffer if they fit, otherwise all excess bytes are flushed to the underlying Write impl.

This fn only returns Ok() if all bytes are either in the internal buffer or already written to the underlying Write impl.

§Errors

Propagated from Write impl

Source

pub fn borrow<'a, T: Write>( &'a mut self, write: &'a mut T, ) -> BorrowedWriteBuffer<'a, T, S>

This fn “borrows”/associates this buffer with a Write impl. The returned BorrowedWriteBuffer has the same lifetime as the Write impl and &mut self combined and can be used as a dyn Write. This might be required to call some library functions which demand a dyn Write as parameter.

Trait Implementations§

Source§

impl<const S: usize> Debug for UnownedWriteBuffer<S>

Source§

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

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

impl Default for UnownedWriteBuffer<0x4000>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const S: usize> Freeze for UnownedWriteBuffer<S>

§

impl<const S: usize> RefUnwindSafe for UnownedWriteBuffer<S>

§

impl<const S: usize> Send for UnownedWriteBuffer<S>

§

impl<const S: usize> Sync for UnownedWriteBuffer<S>

§

impl<const S: usize> Unpin for UnownedWriteBuffer<S>

§

impl<const S: usize> UnwindSafe for UnownedWriteBuffer<S>

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> 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, 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.