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));
}

Implementations on Foreign Types§

source§

impl<T> EncodeLike<PhantomData<T>> for PhantomData<T>

source§

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

source§

impl EncodeLike<&[u8]> for Bytes

source§

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

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

source§

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

source§

impl EncodeLike<u8> for u8

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<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<T: Encode> EncodeLike<T> for &T

source§

impl EncodeLike<u64> for u64

source§

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

source§

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

source§

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

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

source§

impl EncodeLike<i32> for i32

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

source§

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

source§

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

source§

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

source§

impl EncodeLike<u128> for u128

source§

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

source§

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

source§

impl EncodeLike<i128> for i128

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

source§

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

source§

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

source§

impl EncodeLike<String> for &str

source§

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

source§

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

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<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<T: EncodeLike<U>, U: Encode> EncodeLike<Vec<U, Global>> for &[T]

source§

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

source§

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

source§

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

source§

impl EncodeLike<f64> for f64

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<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<K: EncodeLike<LikeK>, LikeK: Encode, V: EncodeLike<LikeV>, LikeV: Encode> EncodeLike<&[(LikeK, LikeV)]> for BTreeMap<K, V>

source§

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

source§

impl EncodeLike<Vec<u8, Global>> for Bytes

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

source§

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

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

source§

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

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<T: ?Sized + Encode> EncodeLike<Rc<T>> for Rc<T>

source§

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

source§

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

source§

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

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

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<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<BinaryHeap<LikeT, Global>> for BinaryHeap<T>

source§

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

source§

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

source§

impl EncodeLike<Bytes> for &[u8]

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 EncodeLike<&str> for String

source§

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

source§

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

source§

impl EncodeLike<i16> for i16

source§

impl EncodeLike<u16> for u16

source§

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

source§

impl EncodeLike<Bytes> for Vec<u8>

source§

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

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<T: Encode> EncodeLike<T> for Arc<T>

source§

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

source§

impl EncodeLike<i8> for i8

source§

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

source§

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

source§

impl EncodeLike<()> for ()

Implementors§

source§

impl EncodeLike<OptionBool> for OptionBool

source§

impl<'a, T> EncodeLike<CompactRef<'a, T>> 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<Compact<T>> 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, Global>> for T

source§

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

source§

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