Trait parity_scale_codec::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));
}

Object Safety§

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 Bytes

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<&[u8]> for Bytes

source§

impl EncodeLike<Bytes> for &[u8]

source§

impl EncodeLike<Bytes> for Vec<u8>

source§

impl EncodeLike<String> for &str

source§

impl EncodeLike<Vec<u8>> for Bytes

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<O: BitOrder, T: BitStore + Encode> EncodeLike for BitBox<T, O>

source§

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

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