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>
impl<const S: usize> UnownedWriteBuffer<S>
Source§impl<const S: usize> UnownedWriteBuffer<S>
impl<const S: usize> UnownedWriteBuffer<S>
Sourcepub const fn available(&self) -> usize
pub const fn available(&self) -> usize
Returns the amount of bytes that can still be written into the internal buffer.
pub const fn size(&self) -> usize
Sourcepub fn flush<T: Write>(&mut self, write: &mut T) -> Result<()>
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
Sourcepub fn try_write<T: Write>(&mut self, buffer: &[u8]) -> usize
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.
Sourcepub fn write<T: Write>(&mut self, write: &mut T, buffer: &[u8]) -> Result<usize>
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
Sourcepub fn write_all<T: Write>(
&mut self,
write: &mut T,
buffer: &[u8],
) -> Result<()>
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
Sourcepub fn borrow<'a, T: Write>(
&'a mut self,
write: &'a mut T,
) -> BorrowedWriteBuffer<'a, T, S> ⓘ
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.