Trait protocol::Parcel

source ·
pub trait Parcel: Sized {
    const TYPE_NAME: &'static str;

    fn read(
        read: &mut dyn Read,
        settings: &Settings,
        hints: &mut Hints
    ) -> Result<Self, Error>; fn write(
        &self,
        write: &mut dyn Write,
        settings: &Settings
    ) -> Result<(), Error>; fn read_new(read: &mut dyn Read, settings: &Settings) -> Result<Self, Error> { ... } fn into_stream(self, settings: &Settings) -> Result<Cursor<Vec<u8>>, Error> { ... } fn from_raw_bytes(bytes: &[u8], settings: &Settings) -> Result<Self, Error> { ... } fn raw_bytes(&self, settings: &Settings) -> Result<Vec<u8>, Error> { ... } fn type_name(&self) -> &'static str { ... } }
Expand description

A value which can be read and written.

All of the expected standard Rust types implement this.

Types that implement Parcel include (not exhaustive):

  • The Rust primitive types
    • u8, i8, u16, i16u64
    • bool, char
    • f32, f64
    • Tuples
      • (T1) where T1: Parcel
      • (T1, T2) where T1: Parcel, T2: Parcel
      • (T1, T2, ... Tn) where T1: Parcel, T2: Parcel, ... Tn: Parcel
    • Arrays
      • [T; 0] where T: Parcel
      • [T; 1] where T: Parcel
      • [T; 2] where T: Parcel
      • [T; 32] where T: Parcel
      • [T; 40] where T: Parcel
      • [T; 42] where T: Parcel
      • [T; 64] where T: Parcel
      • [T; 1024] where T: Parcel
    • String
    • Option<T: Parcel>
    • Box<T: Parcel>
    • Smart pointers
      • std::rc::Rc
      • std::sync::Arc
    • std::collections
      • Vec<T: Parcel>
      • VecDeque<T: Parcel>
      • HashMap<T: Parcel>
      • BTreeMap<T: Parcel>

Required Associated Constants§

The textual name of the type.

Required Methods§

Reads a value from a stream.

Parameters:

  • hints - a list of hints accessible by the current parcel chain only.

Blocks until a value is received.

Writes a value to a stream.

Provided Methods§

Reads a new item with a fresh set of hints.

Blocks until a value is received.

Convers the value into a byte stream that implements std::io::Read.

Parses a new value from its raw byte representation.

Returns Err if the bytes represent an invalid value.

Gets the raw byte representation of the value.

Gets the name of the type; Parcel::TYPE_NAME.

Implementations on Foreign Types§

Implementors§