Trait gstd::prelude::Encode

pub trait Encode {
    // Provided methods
    fn size_hint(&self) -> usize { ... }
    fn encode_to<T>(&self, dest: &mut T)
       where T: Output + ?Sized { ... }
    fn encode(&self) -> Vec<u8>  { ... }
    fn using_encoded<R, F>(&self, f: F) -> R
       where F: FnOnce(&[u8]) -> 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§

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.

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

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

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

Convert self to an owned vector.

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

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

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§

§

impl Encode for bool

§

fn size_hint(&self) -> usize

§

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

§

impl Encode for f32

§

fn size_hint(&self) -> usize

§

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

§

impl Encode for f64

§

fn size_hint(&self) -> usize

§

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

§

impl Encode for i8

§

fn size_hint(&self) -> usize

§

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

§

impl Encode for i16

§

fn size_hint(&self) -> usize

§

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

§

impl Encode for i32

§

fn size_hint(&self) -> usize

§

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

§

impl Encode for i64

§

fn size_hint(&self) -> usize

§

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

§

impl Encode for i128

§

fn size_hint(&self) -> usize

§

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

§

impl Encode for str

§

fn size_hint(&self) -> usize

§

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

§

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

§

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

§

impl Encode for u8

§

fn size_hint(&self) -> usize

§

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

§

impl Encode for u16

§

fn size_hint(&self) -> usize

§

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

§

impl Encode for u32

§

fn size_hint(&self) -> usize

§

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

§

impl Encode for u64

§

fn size_hint(&self) -> usize

§

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

§

impl Encode for u128

§

fn size_hint(&self) -> usize

§

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

§

impl Encode for ()

§

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

§

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

§

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

§

impl Encode for H128

§

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

§

impl Encode for H160

§

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

§

impl Encode for H256

§

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

§

impl Encode for H384

§

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

§

impl Encode for H512

§

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

§

impl Encode for H768

§

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

§

impl Encode for PortableRegistry

§

fn size_hint(&self) -> usize

§

fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
where __CodecOutputEdqy: Output + ?Sized,

§

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

§

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

§

impl Encode for PortableType

§

fn size_hint(&self) -> usize

§

fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
where __CodecOutputEdqy: Output + ?Sized,

§

impl Encode for TypeDefPrimitive

§

fn size_hint(&self) -> usize

§

fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
where __CodecOutputEdqy: Output + ?Sized,

§

impl Encode for U128

§

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

§

impl Encode for U256

§

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

§

impl Encode for U512

§

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

§

impl<A0, B0, C0, D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0> Encode for (A0, B0, C0, D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)
where 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,

§

fn size_hint(&self) -> usize

§

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

§

impl<B0, C0, D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0> Encode for (B0, C0, D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)
where 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,

§

fn size_hint(&self) -> usize

§

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

§

impl<C0, D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0> Encode for (C0, D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)
where 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,

§

fn size_hint(&self) -> usize

§

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

§

impl<D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0> Encode for (D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)
where 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,

§

fn size_hint(&self) -> usize

§

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

§

impl<E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0> Encode for (E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)
where 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,

§

fn size_hint(&self) -> usize

§

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

§

impl<F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0> Encode for (F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)
where 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,

§

fn size_hint(&self) -> usize

§

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

§

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

§

fn size_hint(&self) -> usize

§

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

§

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

§

fn size_hint(&self) -> usize

§

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

§

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

§

fn size_hint(&self) -> usize

§

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

§

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

§

fn size_hint(&self) -> usize

§

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

§

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

§

fn size_hint(&self) -> usize

§

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

§

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

§

fn size_hint(&self) -> usize

§

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

§

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

§

fn size_hint(&self) -> usize

§

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

§

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

§

fn size_hint(&self) -> usize

§

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

§

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

§

fn size_hint(&self) -> usize

§

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

§

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

§

fn size_hint(&self) -> usize

§

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

§

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

§

fn size_hint(&self) -> usize

§

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

§

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

§

fn size_hint(&self) -> usize

§

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

§

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

§

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

§

impl<T> Encode for [T]
where T: Encode,

§

fn size_hint(&self) -> usize

§

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

§

impl<T> Encode for Field<T>
where T: Form, Option<<T as Form>::String>: Encode, <T as Form>::Type: Encode, Vec<<T as Form>::String>: Encode,

§

fn size_hint(&self) -> usize

§

fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
where __CodecOutputEdqy: Output + ?Sized,

§

impl<T> Encode for Path<T>
where T: Form, Vec<<T as Form>::String>: Encode,

§

fn size_hint(&self) -> usize

§

fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
where __CodecOutputEdqy: Output + ?Sized,

§

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

§

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

§

impl<T> Encode for Type<T>
where T: Form, Path<T>: Encode, Vec<TypeParameter<T>>: Encode, TypeDef<T>: Encode, Vec<<T as Form>::String>: Encode,

§

fn size_hint(&self) -> usize

§

fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
where __CodecOutputEdqy: Output + ?Sized,

§

impl<T> Encode for TypeDef<T>
where T: Form, TypeDefComposite<T>: Encode, TypeDefVariant<T>: Encode, TypeDefSequence<T>: Encode, TypeDefArray<T>: Encode, TypeDefTuple<T>: Encode, TypeDefCompact<T>: Encode, TypeDefBitSequence<T>: Encode,

§

fn size_hint(&self) -> usize

§

fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
where __CodecOutputEdqy: Output + ?Sized,

§

impl<T> Encode for TypeDefArray<T>
where T: Form, <T as Form>::Type: Encode,

§

fn size_hint(&self) -> usize

§

fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
where __CodecOutputEdqy: Output + ?Sized,

§

impl<T> Encode for TypeDefBitSequence<T>
where T: Form, <T as Form>::Type: Encode,

§

fn size_hint(&self) -> usize

§

fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
where __CodecOutputEdqy: Output + ?Sized,

§

impl<T> Encode for TypeDefCompact<T>
where T: Form, <T as Form>::Type: Encode,

§

fn size_hint(&self) -> usize

§

fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
where __CodecOutputEdqy: Output + ?Sized,

§

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

§

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

§

impl<T> Encode for TypeDefComposite<T>
where T: Form, Vec<Field<T>>: Encode,

§

fn size_hint(&self) -> usize

§

fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
where __CodecOutputEdqy: Output + ?Sized,

§

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

§

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

§

impl<T> Encode for TypeDefSequence<T>
where T: Form, <T as Form>::Type: Encode,

§

fn size_hint(&self) -> usize

§

fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
where __CodecOutputEdqy: Output + ?Sized,

§

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

§

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

§

impl<T> Encode for TypeDefTuple<T>
where T: Form, Vec<<T as Form>::Type>: Encode,

§

fn size_hint(&self) -> usize

§

fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
where __CodecOutputEdqy: Output + ?Sized,

§

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

§

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

§

impl<T> Encode for TypeDefVariant<T>
where T: Form, Vec<Variant<T>>: Encode,

§

fn size_hint(&self) -> usize

§

fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
where __CodecOutputEdqy: Output + ?Sized,

§

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

§

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

§

impl<T> Encode for TypeParameter<T>
where T: Form, <T as Form>::String: Encode, Option<<T as Form>::Type>: Encode,

§

fn size_hint(&self) -> usize

§

fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
where __CodecOutputEdqy: Output + ?Sized,

§

impl<T> Encode for UntrackedSymbol<T>
where PhantomData<fn() -> T>: Encode,

§

fn size_hint(&self) -> usize

§

fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
where __CodecOutputEdqy: Output + ?Sized,

§

impl<T> Encode for Variant<T>
where T: Form, <T as Form>::String: Encode, Vec<Field<T>>: Encode, Vec<<T as Form>::String>: Encode,

§

fn size_hint(&self) -> usize

§

fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy )
where __CodecOutputEdqy: Output + ?Sized,

§

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

§

fn size_hint(&self) -> usize

§

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

Implementors§

§

impl Encode for ErrorReplyReason

§

impl Encode for ExtError

§

impl Encode for ReplyCode

§

impl Encode for SignalCode

§

impl Encode for SimpleExecutionError

§

impl Encode for SimpleProgramCreationError

§

impl Encode for SuccessReplyReason

source§

impl Encode for ActorId

source§

impl Encode for CodeId

source§

impl Encode for MessageId

source§

impl Encode for Reservation

source§

impl Encode for ReservationId

source§

impl Encode for Reservations

§

impl Encode for NonZeroI8

§

impl Encode for NonZeroI16

§

impl Encode for NonZeroI32

§

impl Encode for NonZeroI64

§

impl Encode for NonZeroI128

§

impl Encode for NonZeroU8

§

impl Encode for NonZeroU16

§

impl Encode for NonZeroU32

§

impl Encode for NonZeroU64

§

impl Encode for NonZeroU128

§

impl Encode for Duration

§

impl Encode for OptionBool

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<T> Encode for PhantomData<T>

§

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

§

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

§

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

§

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

§

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