Trait parity_scale_codec::EncodeLike [−][src]
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
impl<T: ?Sized + Encode> EncodeLike<Box<T, Global>> for Box<T>
[src]
impl<T: Encode> EncodeLike<T> for Box<T>
[src]
impl<T: ?Sized + Encode> EncodeLike<&'_ T> for &T
[src]
impl<T: Encode> EncodeLike<T> for &T
[src]
impl<T: Encode> EncodeLike<T> for &&T
[src]
impl<T: ?Sized + Encode> EncodeLike<&'_ mut T> for &mut T
[src]
impl<T: Encode> EncodeLike<T> for &mut T
[src]
impl<'a, T: ToOwned + Encode + ?Sized> EncodeLike<Cow<'a, T>> for Cow<'a, T>
[src]
impl<'a, T: ToOwned + Encode> EncodeLike<T> for Cow<'a, T>
[src]
impl<T: ?Sized + Encode> EncodeLike<Arc<T>> for Arc<T>
[src]
impl<T: Encode> EncodeLike<T> for Arc<T>
[src]
impl<T: ?Sized + Encode> EncodeLike<Rc<T>> for Rc<T>
[src]
impl<T: Encode> EncodeLike<T> for Rc<T>
[src]
impl EncodeLike<String> for String
[src]
impl EncodeLike<&'_ str> for String
[src]
impl EncodeLike<String> for &str
[src]
impl<T, LikeT, E, LikeE> EncodeLike<Result<LikeT, LikeE>> for Result<T, E> where
T: EncodeLike<LikeT>,
LikeT: Encode,
E: EncodeLike<LikeE>,
LikeE: Encode,
[src]
T: EncodeLike<LikeT>,
LikeT: Encode,
E: EncodeLike<LikeE>,
LikeE: Encode,
impl<T: EncodeLike<U>, U: Encode> EncodeLike<Option<U>> for Option<T>
[src]
impl<T: EncodeLike<U>, U: Encode, const N: usize> EncodeLike<[U; N]> for [T; N]
[src]
impl<T> EncodeLike<PhantomData<T>> for PhantomData<T>
[src]
impl<T: EncodeLike<U>, U: Encode> EncodeLike<Vec<U, Global>> for Vec<T>
[src]
impl<T: EncodeLike<U>, U: Encode> EncodeLike<&'_ [U]> for Vec<T>
[src]
impl<T: EncodeLike<U>, U: Encode> EncodeLike<Vec<U, Global>> for &[T]
[src]
impl<K: EncodeLike<LikeK>, LikeK: Encode, V: EncodeLike<LikeV>, LikeV: Encode> EncodeLike<BTreeMap<LikeK, LikeV>> for BTreeMap<K, V>
[src]
impl<K: EncodeLike<LikeK>, LikeK: Encode, V: EncodeLike<LikeV>, LikeV: Encode> EncodeLike<&'_ [(LikeK, LikeV)]> for BTreeMap<K, V>
[src]
impl<K: EncodeLike<LikeK>, LikeK: Encode, V: EncodeLike<LikeV>, LikeV: Encode> EncodeLike<BTreeMap<LikeK, LikeV>> for &[(K, V)]
[src]
impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<BTreeSet<LikeT>> for BTreeSet<T>
[src]
impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<&'_ [(LikeT,)]> for BTreeSet<T>
[src]
impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<BTreeSet<LikeT>> for &[(T,)]
[src]
impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<LinkedList<LikeT>> for LinkedList<T>
[src]
impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<&'_ [(LikeT,)]> for LinkedList<T>
[src]
impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<LinkedList<LikeT>> for &[(T,)]
[src]
impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<BinaryHeap<LikeT>> for BinaryHeap<T>
[src]
impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<&'_ [(LikeT,)]> for BinaryHeap<T>
[src]
impl<T: EncodeLike<LikeT>, LikeT: Encode> EncodeLike<BinaryHeap<LikeT>> for &[(T,)]
[src]
impl<T: Encode> EncodeLike<VecDeque<T>> for VecDeque<T>
[src]
impl<T: EncodeLike<U>, U: Encode> EncodeLike<&'_ [U]> for VecDeque<T>
[src]
impl<T: EncodeLike<U>, U: Encode> EncodeLike<VecDeque<U>> for &[T]
[src]
impl<T: EncodeLike<U>, U: Encode> EncodeLike<Vec<U, Global>> for VecDeque<T>
[src]
impl<T: EncodeLike<U>, U: Encode> EncodeLike<VecDeque<U>> for Vec<T>
[src]
impl EncodeLike<()> for ()
[src]
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)
[src]
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)
[src]
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)
[src]
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)
[src]
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)
[src]
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)
[src]
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)
[src]
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)
[src]
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)
[src]
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)
[src]
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)
[src]
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)
[src]
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)
[src]
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)
[src]
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)
[src]
impl<P0: EncodeLike<P1>, P1: Encode, Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(P1, Q1, R1)> for (P0, Q0, R0)
[src]
impl<Q0: EncodeLike<Q1>, Q1: Encode, R0: EncodeLike<R1>, R1: Encode> EncodeLike<(Q1, R1)> for (Q0, R0)
[src]
impl<R0: EncodeLike<R1>, R1: Encode> EncodeLike<(R1,)> for (R0,)
[src]
impl EncodeLike<u16> for u16
[src]
impl EncodeLike<u32> for u32
[src]
impl EncodeLike<u64> for u64
[src]
impl EncodeLike<u128> for u128
[src]
impl EncodeLike<i16> for i16
[src]
impl EncodeLike<i32> for i32
[src]
impl EncodeLike<i64> for i64
[src]
impl EncodeLike<i128> for i128
[src]
impl EncodeLike<u8> for u8
[src]
impl EncodeLike<i8> for i8
[src]
impl EncodeLike<bool> for bool
[src]
impl EncodeLike<Duration> for Duration
[src]
Loading content...Implementors
impl EncodeLike<OptionBool> for OptionBool
[src]
impl<'a, T: ToOwned + Encode> EncodeLike<Cow<'a, T>> for T
[src]
impl<'a, T: EncodeLike<U>, U: Encode> EncodeLike<U> for &Ref<'a, T, U>
[src]
impl<'a, T: EncodeLike<U>, U: Encode> EncodeLike<U> for Ref<'a, T, U>
[src]
impl<T> EncodeLike<Compact<T>> for Compact<T> where
CompactRef<'a, T>: Encode,
[src]
CompactRef<'a, T>: Encode,