parity_scale_codec

Trait EncodeLike

Source
pub trait EncodeLike<T: Encode = Self>: Sized + Encode { }
Expand description

A marker trait that tells the compiler that a type encode to the same representation as another type.

E.g. Vec<u8> has the same encoded representation as &[u8].

§Example

fn encode_like<T: Encode, R: EncodeLike<T>>(data: &R) {
    data.encode(); // Valid `T` encoded value.
}

fn main() {
    // Just pass the a reference to the normal tuple.
    encode_like::<(u32, u32), _>(&(1u32, 2u32));
    // Pass a tuple of references
    encode_like::<(u32, u32), _>(&(&1u32, &2u32));
    // Pass a tuple of a reference and a value.
    encode_like::<(u32, u32), _>(&(&1u32, 2u32));
}

§Warning

The relation is not symetric, T implements EncodeLike<U> does not mean U has same representation as T. For instance we could imaging a non zero integer to be encoded to the same representation as the said integer but not the other way around.

§Limitation

Not all possible implementations of EncodeLike are implemented (for instance Box<Box<u32>> does not implement EncodeLike<u32>). To bypass this issue either open a PR to add the new combination or use Ref reference wrapper or define your own wrapper and implement EncodeLike on it as such:

fn encode_like<T: Encode, R: EncodeLike<T>>(data: &R) {
    data.encode(); // Valid `T` encoded value.
}

struct MyWrapper<'a>(&'a (Box<Box<u32>>, u32));
impl<'a> core::ops::Deref for MyWrapper<'a> { // Or use derive_deref crate
    type Target = (Box<Box<u32>>, u32);
    fn deref(&self) -> &Self::Target { &self.0 }
}

impl<'a> parity_scale_codec::WrapperTypeEncode for MyWrapper<'a> {}
impl<'a> parity_scale_codec::EncodeLike<(u32, u32)> for MyWrapper<'a> {}

fn main() {
    let v = (Box::new(Box::new(0)), 0);
    encode_like::<(u32, u32), _>(&MyWrapper(&v));
}

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 EncodeLike for bool

Source§

impl EncodeLike for f32

Source§

impl EncodeLike for f64

Source§

impl EncodeLike for i8

Source§

impl EncodeLike for i16

Source§

impl EncodeLike for i32

Source§

impl EncodeLike for i64

Source§

impl EncodeLike for i128

Source§

impl EncodeLike for u8

Source§

impl EncodeLike for u16

Source§

impl EncodeLike for u32

Source§

impl EncodeLike for u64

Source§

impl EncodeLike for u128

Source§

impl EncodeLike for ()

Source§

impl EncodeLike for String

Source§

impl EncodeLike for Duration

Source§

impl EncodeLike for NonZeroI8

Source§

impl EncodeLike for NonZeroI16

Source§

impl EncodeLike for NonZeroI32

Source§

impl EncodeLike for NonZeroI64

Source§

impl EncodeLike for NonZeroI128

Source§

impl EncodeLike for NonZeroU8

Source§

impl EncodeLike for NonZeroU16

Source§

impl EncodeLike for NonZeroU32

Source§

impl EncodeLike for NonZeroU64

Source§

impl EncodeLike for NonZeroU128

Source§

impl EncodeLike<&str> for String

Source§

impl EncodeLike<String> for &str

Source§

impl<'a, T: ToOwned + Encode + ?Sized> EncodeLike for Cow<'a, T>

Source§

impl<'a, T: ToOwned + Encode> EncodeLike<T> for Cow<'a, T>

Source§

impl<A0: EncodeLike<A1>, A1: Encode, B0: EncodeLike<B1>, B1: Encode, C0: EncodeLike<C1>, C1: Encode, D0: EncodeLike<D1>, D1: Encode, E0: EncodeLike<E1>, E1: Encode, F0: EncodeLike<F1>, F1: Encode, G0: EncodeLike<G1>, G1: Encode, H0: EncodeLike<H1>, H1: Encode, I0: EncodeLike<I1>, I1: Encode, J0: EncodeLike<J1>, J1: Encode, K0: EncodeLike<K1>, K1: Encode, L0: EncodeLike<L1>, L1: Encode, M0: EncodeLike<M1>, M1: Encode, N0: EncodeLike<N1>, N1: Encode, O0: EncodeLike<O1>, O1: Encode, P0: EncodeLike<P1>, P1: Encode, Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(A1, B1, C1, D1, E1, F1, G1, H1, I1, J1, K1, L1, M1, N1, O1, P1, Q1, R1)> for (A0, B0, C0, D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

Source§

impl<B0: EncodeLike<B1>, B1: Encode, C0: EncodeLike<C1>, C1: Encode, D0: EncodeLike<D1>, D1: Encode, E0: EncodeLike<E1>, E1: Encode, F0: EncodeLike<F1>, F1: Encode, G0: EncodeLike<G1>, G1: Encode, H0: EncodeLike<H1>, H1: Encode, I0: EncodeLike<I1>, I1: Encode, J0: EncodeLike<J1>, J1: Encode, K0: EncodeLike<K1>, K1: Encode, L0: EncodeLike<L1>, L1: Encode, M0: EncodeLike<M1>, M1: Encode, N0: EncodeLike<N1>, N1: Encode, O0: EncodeLike<O1>, O1: Encode, P0: EncodeLike<P1>, P1: Encode, Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(B1, C1, D1, E1, F1, G1, H1, I1, J1, K1, L1, M1, N1, O1, P1, Q1, R1)> for (B0, C0, D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

Source§

impl<C0: EncodeLike<C1>, C1: Encode, D0: EncodeLike<D1>, D1: Encode, E0: EncodeLike<E1>, E1: Encode, F0: EncodeLike<F1>, F1: Encode, G0: EncodeLike<G1>, G1: Encode, H0: EncodeLike<H1>, H1: Encode, I0: EncodeLike<I1>, I1: Encode, J0: EncodeLike<J1>, J1: Encode, K0: EncodeLike<K1>, K1: Encode, L0: EncodeLike<L1>, L1: Encode, M0: EncodeLike<M1>, M1: Encode, N0: EncodeLike<N1>, N1: Encode, O0: EncodeLike<O1>, O1: Encode, P0: EncodeLike<P1>, P1: Encode, Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(C1, D1, E1, F1, G1, H1, I1, J1, K1, L1, M1, N1, O1, P1, Q1, R1)> for (C0, D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

Source§

impl<D0: EncodeLike<D1>, D1: Encode, E0: EncodeLike<E1>, E1: Encode, F0: EncodeLike<F1>, F1: Encode, G0: EncodeLike<G1>, G1: Encode, H0: EncodeLike<H1>, H1: Encode, I0: EncodeLike<I1>, I1: Encode, J0: EncodeLike<J1>, J1: Encode, K0: EncodeLike<K1>, K1: Encode, L0: EncodeLike<L1>, L1: Encode, M0: EncodeLike<M1>, M1: Encode, N0: EncodeLike<N1>, N1: Encode, O0: EncodeLike<O1>, O1: Encode, P0: EncodeLike<P1>, P1: Encode, Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(D1, E1, F1, G1, H1, I1, J1, K1, L1, M1, N1, O1, P1, Q1, R1)> for (D0, E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

Source§

impl<E0: EncodeLike<E1>, E1: Encode, F0: EncodeLike<F1>, F1: Encode, G0: EncodeLike<G1>, G1: Encode, H0: EncodeLike<H1>, H1: Encode, I0: EncodeLike<I1>, I1: Encode, J0: EncodeLike<J1>, J1: Encode, K0: EncodeLike<K1>, K1: Encode, L0: EncodeLike<L1>, L1: Encode, M0: EncodeLike<M1>, M1: Encode, N0: EncodeLike<N1>, N1: Encode, O0: EncodeLike<O1>, O1: Encode, P0: EncodeLike<P1>, P1: Encode, Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(E1, F1, G1, H1, I1, J1, K1, L1, M1, N1, O1, P1, Q1, R1)> for (E0, F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

Source§

impl<F0: EncodeLike<F1>, F1: Encode, G0: EncodeLike<G1>, G1: Encode, H0: EncodeLike<H1>, H1: Encode, I0: EncodeLike<I1>, I1: Encode, J0: EncodeLike<J1>, J1: Encode, K0: EncodeLike<K1>, K1: Encode, L0: EncodeLike<L1>, L1: Encode, M0: EncodeLike<M1>, M1: Encode, N0: EncodeLike<N1>, N1: Encode, O0: EncodeLike<O1>, O1: Encode, P0: EncodeLike<P1>, P1: Encode, Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(F1, G1, H1, I1, J1, K1, L1, M1, N1, O1, P1, Q1, R1)> for (F0, G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

Source§

impl<G0: EncodeLike<G1>, G1: Encode, H0: EncodeLike<H1>, H1: Encode, I0: EncodeLike<I1>, I1: Encode, J0: EncodeLike<J1>, J1: Encode, K0: EncodeLike<K1>, K1: Encode, L0: EncodeLike<L1>, L1: Encode, M0: EncodeLike<M1>, M1: Encode, N0: EncodeLike<N1>, N1: Encode, O0: EncodeLike<O1>, O1: Encode, P0: EncodeLike<P1>, P1: Encode, Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(G1, H1, I1, J1, K1, L1, M1, N1, O1, P1, Q1, R1)> for (G0, H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

Source§

impl<H0: EncodeLike<H1>, H1: Encode, I0: EncodeLike<I1>, I1: Encode, J0: EncodeLike<J1>, J1: Encode, K0: EncodeLike<K1>, K1: Encode, L0: EncodeLike<L1>, L1: Encode, M0: EncodeLike<M1>, M1: Encode, N0: EncodeLike<N1>, N1: Encode, O0: EncodeLike<O1>, O1: Encode, P0: EncodeLike<P1>, P1: Encode, Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(H1, I1, J1, K1, L1, M1, N1, O1, P1, Q1, R1)> for (H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

Source§

impl<I0: EncodeLike<I1>, I1: Encode, J0: EncodeLike<J1>, J1: Encode, K0: EncodeLike<K1>, K1: Encode, L0: EncodeLike<L1>, L1: Encode, M0: EncodeLike<M1>, M1: Encode, N0: EncodeLike<N1>, N1: Encode, O0: EncodeLike<O1>, O1: Encode, P0: EncodeLike<P1>, P1: Encode, Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(I1, J1, K1, L1, M1, N1, O1, P1, Q1, R1)> for (I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)

Source§

impl<J0: EncodeLike<J1>, J1: Encode, K0: EncodeLike<K1>, K1: Encode, L0: EncodeLike<L1>, L1: Encode, M0: EncodeLike<M1>, M1: Encode, N0: EncodeLike<N1>, N1: Encode, O0: EncodeLike<O1>, O1: Encode, P0: EncodeLike<P1>, P1: Encode, Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(J1, K1, L1, M1, N1, O1, P1, Q1, R1)> for (J0, K0, L0, M0, N0, O0, P0, Q0, R0)

Source§

impl<K0: EncodeLike<K1>, K1: Encode, L0: EncodeLike<L1>, L1: Encode, M0: EncodeLike<M1>, M1: Encode, N0: EncodeLike<N1>, N1: Encode, O0: EncodeLike<O1>, O1: Encode, P0: EncodeLike<P1>, P1: Encode, Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(K1, L1, M1, N1, O1, P1, Q1, R1)> for (K0, L0, M0, N0, O0, P0, Q0, R0)

Source§

impl<K: EncodeLike<LikeK>, LikeK: Encode, V: EncodeLike<LikeV>, LikeV: Encode> EncodeLike<&[(LikeK, LikeV)]> for BTreeMap<K, V>

Source§

impl<K: EncodeLike<LikeK>, LikeK: Encode, V: EncodeLike<LikeV>, LikeV: Encode> EncodeLike<BTreeMap<LikeK, LikeV>> for &[(K, V)]

Source§

impl<K: EncodeLike<LikeK>, LikeK: Encode, V: EncodeLike<LikeV>, LikeV: Encode> EncodeLike<BTreeMap<LikeK, LikeV>> for BTreeMap<K, V>

Source§

impl<L0: EncodeLike<L1>, L1: Encode, M0: EncodeLike<M1>, M1: Encode, N0: EncodeLike<N1>, N1: Encode, O0: EncodeLike<O1>, O1: Encode, P0: EncodeLike<P1>, P1: Encode, Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(L1, M1, N1, O1, P1, Q1, R1)> for (L0, M0, N0, O0, P0, Q0, R0)

Source§

impl<M0: EncodeLike<M1>, M1: Encode, N0: EncodeLike<N1>, N1: Encode, O0: EncodeLike<O1>, O1: Encode, P0: EncodeLike<P1>, P1: Encode, Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(M1, N1, O1, P1, Q1, R1)> for (M0, N0, O0, P0, Q0, R0)

Source§

impl<N0: EncodeLike<N1>, N1: Encode, O0: EncodeLike<O1>, O1: Encode, P0: EncodeLike<P1>, P1: Encode, Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(N1, O1, P1, Q1, R1)> for (N0, O0, P0, Q0, R0)

Source§

impl<O0: EncodeLike<O1>, O1: Encode, P0: EncodeLike<P1>, P1: Encode, Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(O1, P1, Q1, R1)> for (O0, P0, Q0, R0)

Source§

impl<P0: EncodeLike<P1>, P1: Encode, Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(P1, Q1, R1)> for (P0, Q0, R0)

Source§

impl<Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(Q1, R1)> for (Q0, R0)

Source§

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

Source§

impl<T> EncodeLike for PhantomData<T>

Source§

impl<T, LikeT, E, LikeE> EncodeLike<Result<LikeT, LikeE>> for Result<T, E>
where T: EncodeLike<LikeT>, LikeT: Encode, E: EncodeLike<LikeE>, LikeE: Encode,

Source§

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

Source§

impl<T: Encode> EncodeLike<T> for &&T

Source§

impl<T: Encode> EncodeLike<T> for &T

Source§

impl<T: Encode> EncodeLike<T> for &mut T

Source§

impl<T: Encode> EncodeLike<T> for Box<T>

Source§

impl<T: Encode> EncodeLike<T> for Rc<T>

Source§

impl<T: Encode> EncodeLike<T> for Arc<T>

Source§

impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<&[(LikeT,)]> for BinaryHeap<T>

Source§

impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<&[(LikeT,)]> for BTreeSet<T>

Source§

impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<&[(LikeT,)]> for LinkedList<T>

Source§

impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<BinaryHeap<LikeT>> for &[(T,)]

Source§

impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<BinaryHeap<LikeT>> for BinaryHeap<T>

Source§

impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<BTreeSet<LikeT>> for &[(T,)]

Source§

impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<BTreeSet<LikeT>> for BTreeSet<T>

Source§

impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<LinkedList<LikeT>> for &[(T,)]

Source§

impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<LinkedList<LikeT>> for LinkedList<T>

Source§

impl<T: EncodeLike<U>, U: Encode> EncodeLike<&[U]> for VecDeque<T>

Source§

impl<T: EncodeLike<U>, U: Encode> EncodeLike<&[U]> for Vec<T>

Source§

impl<T: EncodeLike<U>, U: Encode> EncodeLike<Option<U>> for Option<T>

Source§

impl<T: EncodeLike<U>, U: Encode> EncodeLike<VecDeque<U>> for &[T]

Source§

impl<T: EncodeLike<U>, U: Encode> EncodeLike<VecDeque<U>> for Vec<T>

Source§

impl<T: EncodeLike<U>, U: Encode> EncodeLike<Vec<U>> for &[T]

Source§

impl<T: EncodeLike<U>, U: Encode> EncodeLike<Vec<U>> for VecDeque<T>

Source§

impl<T: EncodeLike<U>, U: Encode> EncodeLike<Vec<U>> for Vec<T>

Source§

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

Source§

impl<T: ?Sized + Encode> EncodeLike for &T

Source§

impl<T: ?Sized + Encode> EncodeLike for &mut T

Source§

impl<T: ?Sized + Encode> EncodeLike for Box<T>

Source§

impl<T: ?Sized + Encode> EncodeLike for Rc<T>

Source§

impl<T: ?Sized + Encode> EncodeLike for Arc<T>

Implementors§

Source§

impl EncodeLike for OptionBool

Source§

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

Source§

impl<'a, T: ToOwned + Encode> EncodeLike<Cow<'a, T>> for T

Source§

impl<'a, T: EncodeLike<U>, U: Encode> EncodeLike<U> for &Ref<'a, T, U>

Source§

impl<'a, T: EncodeLike<U>, U: Encode> EncodeLike<U> for Ref<'a, T, U>

Source§

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

Source§

impl<T: Encode> EncodeLike<&&T> for T

Source§

impl<T: Encode> EncodeLike<&T> for T

Source§

impl<T: Encode> EncodeLike<&mut T> for T

Source§

impl<T: Encode> EncodeLike<Box<T>> for T

Source§

impl<T: Encode> EncodeLike<Rc<T>> for T

Source§

impl<T: Encode> EncodeLike<Arc<T>> for T