Trait musli::Buf

source ·
pub trait Buf {
    // Required methods
    fn write(&mut self, bytes: &[u8]) -> bool;
    fn len(&self) -> usize;
    fn as_slice(&self) -> &[u8] ;
    fn write_fmt(&mut self, arguments: Arguments<'_>) -> Result<(), Error>;

    // Provided methods
    fn write_buffer<B>(&mut self, other: B) -> bool
       where B: Buf { ... }
    fn push(&mut self, byte: u8) -> bool { ... }
    fn is_empty(&self) -> bool { ... }
}
Expand description

A buffer allocated from a context.

Buffers are allocated through an allocator using Allocator::alloc.

Required Methods§

source

fn write(&mut self, bytes: &[u8]) -> bool

Write the given number of bytes.

Returns true if the bytes could be successfully written. A false value indicates that we are out of buffer capacity.

source

fn len(&self) -> usize

Get the length of the buffer in bytes.

source

fn as_slice(&self) -> &[u8]

Get the buffer as its initialized slice.

source

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

Try to write a format string into the buffer.

Provided Methods§

source

fn write_buffer<B>(&mut self, other: B) -> bool
where B: Buf,

Write a buffer of the same type onto the current buffer.

This allows allocators to provide more efficient means of extending the current buffer with one provided from the same allocator.

source

fn push(&mut self, byte: u8) -> bool

Write a single byte.

Returns true if the bytes could be successfully written. A false value indicates that we are out of buffer capacity.

source

fn is_empty(&self) -> bool

Test if the buffer is empty.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Buf for [u8]

source§

fn write(&mut self, _: &[u8]) -> bool

source§

fn len(&self) -> usize

source§

fn is_empty(&self) -> bool

source§

fn as_slice(&self) -> &[u8]

source§

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

Implementors§