FrameBuilder

Trait FrameBuilder 

Source
pub trait FrameBuilder {
    type OwnedFrameType;

    // Required methods
    fn write_to<W: Write>(&self, writer: &mut W) -> Result<usize, Error>;
    fn write_into(&self, into: &mut [u8]) -> Result<usize, Error>;
    fn expected_size(&self) -> Option<usize>;
    fn as_owned_frame(&self) -> Self::OwnedFrameType;

    // Provided method
    fn as_bytes(&self) -> Bytes { ... }
}
Expand description

A frame builder can wrap another frame (or just data), and can be wrapped into another frame. The runtime hierarchy is the same as persisted.

Ex: Stored: SizedFrame(MultihashFrame(Data)) Runtime: SizedFrameBuilder(MultihashFrameBuilder(Data))

Required Associated Types§

Required Methods§

Source

fn write_to<W: Write>(&self, writer: &mut W) -> Result<usize, Error>

Write the frame to the given writer

Source

fn write_into(&self, into: &mut [u8]) -> Result<usize, Error>

Write the frame into the given bytes slice

Source

fn expected_size(&self) -> Option<usize>

Expected size of the frame (in bytes). Optional since some kind of frames have an unknown size until they are serialized (ex: capnp)

Source

fn as_owned_frame(&self) -> Self::OwnedFrameType

Creates a owned version of this frame, which is usually a FrameReader implementation

Provided Methods§

Source

fn as_bytes(&self) -> Bytes

Writes the frame into a in-memory buffer and returns it.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§