FrameReader

Trait FrameReader 

Source
pub trait FrameReader {
    type OwnedType: FrameReader;

    // Required methods
    fn exposed_data(&self) -> &[u8] ;
    fn whole_data(&self) -> &[u8] ;
    fn to_owned_frame(&self) -> Self::OwnedType;

    // Provided methods
    fn whole_data_size(&self) -> usize { ... }
    fn copy_to<W: Write>(&self, writer: &mut W) -> Result<(), Error> { ... }
    fn copy_into(&self, into: &mut [u8]) -> Result<usize, Error> { ... }
}
Expand description

Represents a frame that either wrap another frame or bytes (vec or slice).

The hierarchy of a FrameReader instances are the opposite of the persisted hierarchy. Ex: Stored: SizedFrame( MultihashFrame( Data ) ) Runtime: Data ( MultiHash ( SizedFrame ) )

The reason for this reversal is that the inner most frame doesn’t know how to extract the bytes from the whole frame. Therefor, the wrapping frame “exposes” the bytes to the inner most frames at runtime.

Required Associated Types§

Required Methods§

Source

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

Data exposed by this frame to inner frame. Ex: sized frame will expose the sized data without encoded size numbers

Source

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

Data of the whole frame, not just the exposed data.

Source

fn to_owned_frame(&self) -> Self::OwnedType

Converts the frame to a owned version (without lifetime)

Provided Methods§

Source

fn whole_data_size(&self) -> usize

Size of the whole data of the frame.

Source

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

Copy the frame into the given writer

Source

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

Copy the frame into the given slice

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§