parity_scale_codec

Trait 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.

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 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<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>,