Trait parity_scale_codec::Encode

source ·
pub trait Encode {
    // Provided methods
    fn size_hint(&self) -> usize { ... }
    fn encode_to<T: Output + ?Sized>(&self, dest: &mut T) { ... }
    fn encode(&self) -> Vec<u8>  { ... }
    fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R { ... }
    fn encoded_size(&self) -> usize { ... }
}
Expand description

Trait that allows zero-copy write of value-references to slices in LE format.

Implementations should override using_encoded for value types and encode_to and size_hint for allocating types. Wrapper types should override all methods.

Provided Methods§

source

fn size_hint(&self) -> usize

If possible give a hint of expected size of the encoding.

This method is used inside default implementation of encode to avoid re-allocations.

source

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

Convert self to a slice and append it to the destination.

source

fn encode(&self) -> Vec<u8>

Convert self to an owned vector.

source

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

Convert self to a slice and then invoke the given closure with it.

source

fn encoded_size(&self) -> usize

Calculates the encoded size.

Should be used when the encoded data isn’t required.

§Note

This works by using a special Output that only tracks the size. So, there are no allocations inside the output. However, this can not prevent allocations that some types are doing inside their own encoding.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Encode for bool

source§

fn size_hint(&self) -> usize

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for f32

source§

fn size_hint(&self) -> usize

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for f64

source§

fn size_hint(&self) -> usize

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for i8

source§

fn size_hint(&self) -> usize

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for i16

source§

fn size_hint(&self) -> usize

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for i32

source§

fn size_hint(&self) -> usize

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for i64

source§

fn size_hint(&self) -> usize

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for i128

source§

fn size_hint(&self) -> usize

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for str

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

fn encode(&self) -> Vec<u8>

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for u8

source§

fn size_hint(&self) -> usize

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for u16

source§

fn size_hint(&self) -> usize

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for u32

source§

fn size_hint(&self) -> usize

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for u64

source§

fn size_hint(&self) -> usize

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for u128

source§

fn size_hint(&self) -> usize

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for ()

source§

fn encode_to<W: Output + ?Sized>(&self, _dest: &mut W)

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

fn encode(&self) -> Vec<u8>

source§

impl Encode for Duration

source§

fn size_hint(&self) -> usize

source§

fn encode(&self) -> Vec<u8>

source§

impl Encode for NonZeroI8

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

fn encode(&self) -> Vec<u8>

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for NonZeroI16

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

fn encode(&self) -> Vec<u8>

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for NonZeroI32

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

fn encode(&self) -> Vec<u8>

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for NonZeroI64

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

fn encode(&self) -> Vec<u8>

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for NonZeroI128

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

fn encode(&self) -> Vec<u8>

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for NonZeroU8

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

fn encode(&self) -> Vec<u8>

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for NonZeroU16

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

fn encode(&self) -> Vec<u8>

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for NonZeroU32

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

fn encode(&self) -> Vec<u8>

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for NonZeroU64

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

fn encode(&self) -> Vec<u8>

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl Encode for NonZeroU128

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

fn encode(&self) -> Vec<u8>

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl<A0: Encode, B0: Encode, C0: Encode, D0: Encode, E0: Encode, F0: Encode, G0: Encode, H0: Encode, I0: Encode, J0: Encode, K0: Encode, L0: Encode, M0: Encode, N0: Encode, O0: Encode, P0: Encode, Q0: Encode, R0: Encode> Encode for (A0, B0, C0, D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

impl<B0: Encode, C0: Encode, D0: Encode, E0: Encode, F0: Encode, G0: Encode, H0: Encode, I0: Encode, J0: Encode, K0: Encode, L0: Encode, M0: Encode, N0: Encode, O0: Encode, P0: Encode, Q0: Encode, R0: Encode> Encode for (B0, C0, D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

impl<C0: Encode, D0: Encode, E0: Encode, F0: Encode, G0: Encode, H0: Encode, I0: Encode, J0: Encode, K0: Encode, L0: Encode, M0: Encode, N0: Encode, O0: Encode, P0: Encode, Q0: Encode, R0: Encode> Encode for (C0, D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

impl<D0: Encode, E0: Encode, F0: Encode, G0: Encode, H0: Encode, I0: Encode, J0: Encode, K0: Encode, L0: Encode, M0: Encode, N0: Encode, O0: Encode, P0: Encode, Q0: Encode, R0: Encode> Encode for (D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

impl<E0: Encode, F0: Encode, G0: Encode, H0: Encode, I0: Encode, J0: Encode, K0: Encode, L0: Encode, M0: Encode, N0: Encode, O0: Encode, P0: Encode, Q0: Encode, R0: Encode> Encode for (E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

impl<F0: Encode, G0: Encode, H0: Encode, I0: Encode, J0: Encode, K0: Encode, L0: Encode, M0: Encode, N0: Encode, O0: Encode, P0: Encode, Q0: Encode, R0: Encode> Encode for (F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

impl<G0: Encode, H0: Encode, I0: Encode, J0: Encode, K0: Encode, L0: Encode, M0: Encode, N0: Encode, O0: Encode, P0: Encode, Q0: Encode, R0: Encode> Encode for (G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

impl<H0: Encode, I0: Encode, J0: Encode, K0: Encode, L0: Encode, M0: Encode, N0: Encode, O0: Encode, P0: Encode, Q0: Encode, R0: Encode> Encode for (H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

impl<I0: Encode, J0: Encode, K0: Encode, L0: Encode, M0: Encode, N0: Encode, O0: Encode, P0: Encode, Q0: Encode, R0: Encode> Encode for (I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

impl<J0: Encode, K0: Encode, L0: Encode, M0: Encode, N0: Encode, O0: Encode, P0: Encode, Q0: Encode, R0: Encode> Encode for (J0, K0, L0, M0, N0, O0, P0, Q0, R0)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

impl<K0: Encode, L0: Encode, M0: Encode, N0: Encode, O0: Encode, P0: Encode, Q0: Encode, R0: Encode> Encode for (K0, L0, M0, N0, O0, P0, Q0, R0)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

impl<K: Encode, V: Encode> Encode for BTreeMap<K, V>

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

impl<L0: Encode, M0: Encode, N0: Encode, O0: Encode, P0: Encode, Q0: Encode, R0: Encode> Encode for (L0, M0, N0, O0, P0, Q0, R0)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

impl<M0: Encode, N0: Encode, O0: Encode, P0: Encode, Q0: Encode, R0: Encode> Encode for (M0, N0, O0, P0, Q0, R0)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

impl<N0: Encode, O0: Encode, P0: Encode, Q0: Encode, R0: Encode> Encode for (N0, O0, P0, Q0, R0)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

impl<O0: Encode, P0: Encode, Q0: Encode, R0: Encode> Encode for (O0, P0, Q0, R0)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

impl<O: BitOrder, T: BitStore + Encode> Encode for BitBox<T, O>

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

impl<O: BitOrder, T: BitStore + Encode> Encode for BitSlice<T, O>

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

impl<O: BitOrder, T: BitStore + Encode> Encode for BitVec<T, O>

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

impl<P0: Encode, Q0: Encode, R0: Encode> Encode for (P0, Q0, R0)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

impl<Q0: Encode, R0: Encode> Encode for (Q0, R0)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

impl<R0: Encode> Encode for (R0,)

source§

fn size_hint(&self) -> usize

source§

fn encode_to<T: Output + ?Sized>(&self, dest: &mut T)

source§

fn encode(&self) -> Vec<u8>

source§

fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R

source§

impl<T> Encode for PhantomData<T>

source§

fn encode_to<W: Output + ?Sized>(&self, _dest: &mut W)

source§

impl<T> Encode for Range<T>
where T: Encode,

source§

fn size_hint(&self) -> usize

source§

fn encode(&self) -> Vec<u8>

source§

impl<T> Encode for RangeInclusive<T>
where T: Encode,

source§

fn size_hint(&self) -> usize

source§

fn encode(&self) -> Vec<u8>

source§

impl<T: Encode> Encode for Option<T>

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

impl<T: Encode> Encode for [T]

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

impl<T: Encode> Encode for BinaryHeap<T>

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

impl<T: Encode> Encode for BTreeSet<T>

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

impl<T: Encode> Encode for LinkedList<T>

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

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

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

impl<T: Encode, E: Encode> Encode for Result<T, E>

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

source§

impl<T: Encode, const N: usize> Encode for [T; N]

source§

fn size_hint(&self) -> usize

source§

fn encode_to<W: Output + ?Sized>(&self, dest: &mut W)

Implementors§

source§

impl Encode for OptionBool

source§

impl<'a> Encode for CompactRef<'a, u8>

source§

impl<'a> Encode for CompactRef<'a, u16>

source§

impl<'a> Encode for CompactRef<'a, u32>

source§

impl<'a> Encode for CompactRef<'a, u64>

source§

impl<'a> Encode for CompactRef<'a, u128>

source§

impl<'a> Encode for CompactRef<'a, ()>

source§

impl<'a, T> Encode for CompactRef<'a, T>
where T: CompactAs, for<'b> CompactRef<'b, T::As>: Encode,

source§

impl<T> Encode for Compact<T>
where for<'a> CompactRef<'a, T>: Encode,

source§

impl<T, X> Encode for X
where T: Encode + ?Sized, X: WrapperTypeEncode<Target = T>,