Trait octseq::builder::OctetsBuilder

source ·
pub trait OctetsBuilder {
    type AppendError: Into<ShortBuf>;

    // Required method
    fn append_slice(&mut self, slice: &[u8]) -> Result<(), Self::AppendError>;
}
Expand description

A buffer to construct an octet sequence.

Octet builders represent a buffer of space available for building an octets sequence by appending the contents of octet slices. The buffers may consist of a predefined amount of space or grow as needed.

Octet builders provide access to the already assembled data through octet slices via their implementations of AsRef<[u8]> and AsMut<[u8]>.

Required Associated Types§

source

type AppendError: Into<ShortBuf>

The error type when appending data fails.

There are exactly two options for this type: Builders where appending never fails use Infallible. Builders with a limited buffer which may have insufficient space for appending use ShortBuf.

The trait bound on the type allows upgrading the error to ShortBuf even for builders with unlimited space. This way, an error type for operations that use a builder doesn’t need to be generic over the append error type and can simply use a variant for anything Into<ShortBuf> instead.

Required Methods§

source

fn append_slice(&mut self, slice: &[u8]) -> Result<(), Self::AppendError>

Appends the content of a slice to the builder.

If there isn’t enough space available for appending the slice, returns an error and leaves the builder alone.

Implementations on Foreign Types§

source§

impl OctetsBuilder for BytesMut

§

type AppendError = Infallible

source§

fn append_slice(&mut self, slice: &[u8]) -> Result<(), Self::AppendError>

source§

impl OctetsBuilder for Vec<u8>

§

type AppendError = Infallible

source§

fn append_slice(&mut self, slice: &[u8]) -> Result<(), Self::AppendError>

source§

impl<'a> OctetsBuilder for Cow<'a, [u8]>

§

type AppendError = Infallible

source§

fn append_slice(&mut self, slice: &[u8]) -> Result<(), Self::AppendError>

source§

impl<'a, T: OctetsBuilder> OctetsBuilder for &'a mut T

§

type AppendError = <T as OctetsBuilder>::AppendError

source§

fn append_slice(&mut self, slice: &[u8]) -> Result<(), Self::AppendError>

source§

impl<A: Array<Item = u8>> OctetsBuilder for SmallVec<A>

§

type AppendError = Infallible

source§

fn append_slice(&mut self, slice: &[u8]) -> Result<(), Self::AppendError>

Implementors§