pub trait EncodeLike<T = Self>: Sized + Encodewhere
T: 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§
impl EncodeLike for TypeDefPrimitive
impl EncodeLike for bool
impl EncodeLike for f32
impl EncodeLike for f64
impl EncodeLike for i8
impl EncodeLike for i16
impl EncodeLike for i32
impl EncodeLike for i64
impl EncodeLike for i128
impl EncodeLike for u8
impl EncodeLike for u16
impl EncodeLike for u32
impl EncodeLike for u64
impl EncodeLike for u128
impl EncodeLike for ()
impl EncodeLike for NonZeroU256
impl EncodeLike for MessageHandle
impl EncodeLike for H128
impl EncodeLike for H160
impl EncodeLike for H256
impl EncodeLike for H384
impl EncodeLike for H512
impl EncodeLike for H768
impl EncodeLike for U128
impl EncodeLike for U256
impl EncodeLike for U512
impl EncodeLike for PortableRegistry
impl EncodeLike for PortableType
impl EncodeLike<String> for &str
impl<A0, A1, B0, B1, C0, C1, D0, D1, E0, E1, F0, F1, G0, G1, H0, H1, I0, I1, J0, J1, K0, K1, L0, L1, M0, M1, N0, N1, O0, O1, P0, P1, Q0, Q1, R0, R1> 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)where
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,
impl<B0, B1, C0, C1, D0, D1, E0, E1, F0, F1, G0, G1, H0, H1, I0, I1, J0, J1, K0, K1, L0, L1, M0, M1, N0, N1, O0, O1, P0, P1, Q0, Q1, R0, R1> 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)where
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,
impl<C0, C1, D0, D1, E0, E1, F0, F1, G0, G1, H0, H1, I0, I1, J0, J1, K0, K1, L0, L1, M0, M1, N0, N1, O0, O1, P0, P1, Q0, Q1, R0, R1> 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)where
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,
impl<D0, D1, E0, E1, F0, F1, G0, G1, H0, H1, I0, I1, J0, J1, K0, K1, L0, L1, M0, M1, N0, N1, O0, O1, P0, P1, Q0, Q1, R0, R1> 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)where
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,
impl<E0, E1, F0, F1, G0, G1, H0, H1, I0, I1, J0, J1, K0, K1, L0, L1, M0, M1, N0, N1, O0, O1, P0, P1, Q0, Q1, R0, R1> 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)where
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,
impl<F0, F1, G0, G1, H0, H1, I0, I1, J0, J1, K0, K1, L0, L1, M0, M1, N0, N1, O0, O1, P0, P1, Q0, Q1, R0, R1> 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)where
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,
impl<G0, G1, H0, H1, I0, I1, J0, J1, K0, K1, L0, L1, M0, M1, N0, N1, O0, O1, P0, P1, Q0, Q1, R0, R1> 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)where
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,
impl<H0, H1, I0, I1, J0, J1, K0, K1, L0, L1, M0, M1, N0, N1, O0, O1, P0, P1, Q0, Q1, R0, R1> EncodeLike<(H1, I1, J1, K1, L1, M1, N1, O1, P1, Q1, R1)> for (H0, I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)where
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,
impl<I0, I1, J0, J1, K0, K1, L0, L1, M0, M1, N0, N1, O0, O1, P0, P1, Q0, Q1, R0, R1> EncodeLike<(I1, J1, K1, L1, M1, N1, O1, P1, Q1, R1)> for (I0, J0, K0, L0, M0, N0, O0, P0, Q0, R0)where
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,
impl<J0, J1, K0, K1, L0, L1, M0, M1, N0, N1, O0, O1, P0, P1, Q0, Q1, R0, R1> EncodeLike<(J1, K1, L1, M1, N1, O1, P1, Q1, R1)> for (J0, K0, L0, M0, N0, O0, P0, Q0, R0)where
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,
impl<K0, K1, L0, L1, M0, M1, N0, N1, O0, O1, P0, P1, Q0, Q1, R0, R1> EncodeLike<(K1, L1, M1, N1, O1, P1, Q1, R1)> for (K0, L0, M0, N0, O0, P0, Q0, R0)where
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,
impl<K, LikeK, V, LikeV> EncodeLike<BTreeMap<LikeK, LikeV>> for &[(K, V)]
impl<L0, L1, M0, M1, N0, N1, O0, O1, P0, P1, Q0, Q1, R0, R1> EncodeLike<(L1, M1, N1, O1, P1, Q1, R1)> for (L0, M0, N0, O0, P0, Q0, R0)where
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,
impl<M0, M1, N0, N1, O0, O1, P0, P1, Q0, Q1, R0, R1> EncodeLike<(M1, N1, O1, P1, Q1, R1)> for (M0, N0, O0, P0, Q0, R0)where
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,
impl<N0, N1, O0, O1, P0, P1, Q0, Q1, R0, R1> EncodeLike<(N1, O1, P1, Q1, R1)> for (N0, O0, P0, Q0, R0)where
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,
impl<O0, O1, P0, P1, Q0, Q1, R0, R1> EncodeLike<(O1, P1, Q1, R1)> for (O0, P0, Q0, R0)where
O0: EncodeLike<O1>,
O1: Encode,
P0: EncodeLike<P1>,
P1: Encode,
Q0: EncodeLike<Q1>,
Q1: Encode,
R0: EncodeLike<R1>,
R1: Encode,
impl<P0, P1, Q0, Q1, R0, R1> EncodeLike<(P1, Q1, R1)> for (P0, Q0, R0)where
P0: EncodeLike<P1>,
P1: Encode,
Q0: EncodeLike<Q1>,
Q1: Encode,
R0: EncodeLike<R1>,
R1: Encode,
impl<Q0, Q1, R0, R1> EncodeLike<(Q1, R1)> for (Q0, R0)
impl<R0, R1> EncodeLike<(R1,)> for (R0,)where
R0: EncodeLike<R1>,
R1: Encode,
impl<T> EncodeLike 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,
impl<T> EncodeLike for &T
impl<T> EncodeLike for &mut T
impl<T> EncodeLike for Arc<T>
impl<T> EncodeLike for UntrackedSymbol<T>
impl<T> EncodeLike for TypeDefComposite<T>
impl<T> EncodeLike for Field<T>
impl<T> EncodeLike for Path<T>
impl<T> EncodeLike for Type<T>
impl<T> EncodeLike for TypeDefArray<T>
impl<T> EncodeLike for TypeDefBitSequence<T>
impl<T> EncodeLike for TypeDefCompact<T>
impl<T> EncodeLike for TypeDefSequence<T>
impl<T> EncodeLike for TypeDefTuple<T>
impl<T> EncodeLike for TypeParameter<T>
impl<T> EncodeLike for TypeDefVariant<T>
impl<T> EncodeLike for Variant<T>
impl<T> EncodeLike<T> for &&Twhere
T: Encode,
impl<T> EncodeLike<T> for &Twhere
T: Encode,
impl<T> EncodeLike<T> for &mut Twhere
T: Encode,
impl<T> EncodeLike<T> for Arc<T>where
T: Encode,
impl<T, LikeT> EncodeLike<BTreeSet<LikeT>> for &[(T,)]where
T: EncodeLike<LikeT>,
LikeT: Encode,
impl<T, LikeT> EncodeLike<BinaryHeap<LikeT>> for &[(T,)]where
T: EncodeLike<LikeT>,
LikeT: Encode,
impl<T, LikeT> EncodeLike<LinkedList<LikeT>> for &[(T,)]where
T: EncodeLike<LikeT>,
LikeT: Encode,
impl<T, U> EncodeLike<VecDeque<U>> for &[T]where
T: EncodeLike<U>,
U: Encode,
impl<T, U> EncodeLike<Vec<U>> for &[T]where
T: EncodeLike<U>,
U: Encode,
impl<T, U, const N: usize> EncodeLike<[U; N]> for [T; N]where
T: EncodeLike<U>,
U: Encode,
Implementors§
impl EncodeLike for ErrorReplyReason
impl EncodeLike for ReplyCode
impl EncodeLike for SignalCode
impl EncodeLike for SimpleExecutionError
impl EncodeLike for SuccessReplyReason
impl EncodeLike for ActorId
impl EncodeLike for CodeId
impl EncodeLike for MessageId
impl EncodeLike for Reservation
ethexe only.impl EncodeLike for ReservationId
impl EncodeLike for Reservations
ethexe only.