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§
Sourcetype AppendError: Into<ShortBuf>
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§
Sourcefn append_slice(&mut self, slice: &[u8]) -> Result<(), Self::AppendError>
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
Available on crate feature bytes only.
impl OctetsBuilder for BytesMut
bytes only.type AppendError = Infallible
fn append_slice(&mut self, slice: &[u8]) -> Result<(), Self::AppendError>
Source§impl OctetsBuilder for Vec<u8>
Available on crate feature std only.
impl OctetsBuilder for Vec<u8>
std only.type AppendError = Infallible
fn append_slice(&mut self, slice: &[u8]) -> Result<(), Self::AppendError>
Source§impl<'a> OctetsBuilder for Cow<'a, [u8]>
Available on crate feature std only.
impl<'a> OctetsBuilder for Cow<'a, [u8]>
std only.type AppendError = Infallible
fn append_slice(&mut self, slice: &[u8]) -> Result<(), Self::AppendError>
Source§impl<'a, T: OctetsBuilder> OctetsBuilder for &'a mut T
impl<'a, T: OctetsBuilder> OctetsBuilder for &'a mut T
type AppendError = <T as OctetsBuilder>::AppendError
fn append_slice(&mut self, slice: &[u8]) -> Result<(), Self::AppendError>
Source§impl<A: Array<Item = u8>> OctetsBuilder for SmallVec<A>
Available on crate feature smallvec only.
impl<A: Array<Item = u8>> OctetsBuilder for SmallVec<A>
smallvec only.