parity_scale_codec

Trait EncodeAppend

Source
pub trait EncodeAppend {
    type Item: Encode;

    // Required method
    fn append_or_new<EncodeLikeItem, I>(
        self_encoded: Vec<u8>,
        iter: I,
    ) -> Result<Vec<u8>, Error>
       where I: IntoIterator<Item = EncodeLikeItem>,
             EncodeLikeItem: EncodeLike<Self::Item>,
             I::IntoIter: ExactSizeIterator;
}
Expand description

Trait that allows to append items to an encoded representation without decoding all previous added items.

Required Associated Types§

Source

type Item: Encode

The item that will be appended.

Required Methods§

Source

fn append_or_new<EncodeLikeItem, I>( self_encoded: Vec<u8>, iter: I, ) -> Result<Vec<u8>, Error>
where I: IntoIterator<Item = EncodeLikeItem>, EncodeLikeItem: EncodeLike<Self::Item>, I::IntoIter: ExactSizeIterator,

Append all items in iter to the given self_encoded representation or if self_encoded value is empty, iter is encoded to the Self representation.

§Example

// Some encoded data
let data = Vec::new();

let item = 8u32;
let encoded = <Vec<u32> as EncodeAppend>::append_or_new(data, std::iter::once(&item)).expect("Adds new element");

// Add multiple element
<Vec<u32> as EncodeAppend>::append_or_new(encoded, &[700u32, 800u32, 10u32]).expect("Adds new elements");

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.

Implementations on Foreign Types§

Source§

impl<T: Encode> EncodeAppend for VecDeque<T>

Source§

type Item = T

Source§

fn append_or_new<EncodeLikeItem, I>( self_encoded: Vec<u8>, iter: I, ) -> Result<Vec<u8>, Error>
where I: IntoIterator<Item = EncodeLikeItem>, EncodeLikeItem: EncodeLike<Self::Item>, I::IntoIter: ExactSizeIterator,

Source§

impl<T: Encode> EncodeAppend for Vec<T>

Source§

type Item = T

Source§

fn append_or_new<EncodeLikeItem, I>( self_encoded: Vec<u8>, iter: I, ) -> Result<Vec<u8>, Error>
where I: IntoIterator<Item = EncodeLikeItem>, EncodeLikeItem: EncodeLike<Self::Item>, I::IntoIter: ExactSizeIterator,

Implementors§