pub trait EncodeAsType {
// Required method
fn encode_as_type_to<R: TypeResolver>(
&self,
type_id: R::TypeId,
types: &R,
out: &mut Vec<u8>,
) -> Result<(), Error>;
// Provided method
fn encode_as_type<R: TypeResolver>(
&self,
type_id: R::TypeId,
types: &R,
) -> Result<Vec<u8>, Error> { ... }
}
Expand description
This trait signals that some static type can possibly be SCALE encoded given some
type_id
and a corresponding TypeResolver
which tells us about the expected encoding.
Required Methods§
sourcefn encode_as_type_to<R: TypeResolver>(
&self,
type_id: R::TypeId,
types: &R,
out: &mut Vec<u8>,
) -> Result<(), Error>
fn encode_as_type_to<R: TypeResolver>( &self, type_id: R::TypeId, types: &R, out: &mut Vec<u8>, ) -> Result<(), Error>
Given some type_id
, types
, a context
and some output target for the SCALE encoded bytes,
attempt to SCALE encode the current value into the type given by type_id
.
Provided Methods§
sourcefn encode_as_type<R: TypeResolver>(
&self,
type_id: R::TypeId,
types: &R,
) -> Result<Vec<u8>, Error>
fn encode_as_type<R: TypeResolver>( &self, type_id: R::TypeId, types: &R, ) -> Result<Vec<u8>, Error>
This is a helper function which internally calls EncodeAsType::encode_as_type_to
. Prefer to
implement that instead.
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.