Skip to main content

Storage

Trait Storage 

Source
pub trait Storage: Deref<Target = [u8]> + DerefMut<Target = [u8]> {
    type Output;

    // Required methods
    fn try_push(&mut self, data: u8) -> Result<()>;
    fn finalize(self) -> Self::Output;

    // Provided method
    fn try_extend(&mut self, data: &[u8]) -> Result<()> { ... }
}
Expand description

Serialization storage, the output medium of the serialization

Serialization buffers can implement this trait to be used as an output with the serializer e.g. whether the data is serialized to a u8 slice, or a Vec<u8, N>.

Required Associated Types§

Source

type Output

What this storage “resolves” to when the serialization is complete, such as a u8 slice, or a Vec<u8, N>.

Required Methods§

Source

fn try_push(&mut self, data: u8) -> Result<()>

Can be used to push a single byte to be modified and/or stored.

Source

fn finalize(self) -> Self::Output

Finalize the serialization process.

Provided Methods§

Source

fn try_extend(&mut self, data: &[u8]) -> Result<()>

Can be implemented when there is a more efficient way of processing multiple bytes at once, such as copying a slice to the output, rather than iterating over one byte at a time.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<'a> Storage for Slice<'a>

Source§

type Output = &'a mut [u8]

Source§

impl<const N: usize> Storage for HVec<N>

Available on crate feature heapless only.
Source§

type Output = Vec<u8, N>