pub trait Component:
Sealed
+ Serialize
+ DeserializeOwned
+ 'static {
const TYPE_CODE: TypeCode;
const SCHEMA_VERSION: u32;
// Provided methods
fn canonical_bytes(&self) -> Vec<u8> ⓘ
where Self: Sized { ... }
fn from_bytes(
version: u32,
bytes: &[u8],
) -> Result<Box<Self>, DeserializeError>
where Self: Sized { ... }
fn approx_size(&self) -> usize
where Self: Sized { ... }
}Expand description
Component — derive-only via #[derive(arkhe_macros::ArkheComponent)].
Default methods use postcard for the canonical-bytes round trip;
the macro only needs to emit Sealed + the const declarations.
Required Associated Constants§
Sourceconst TYPE_CODE: TypeCode
const TYPE_CODE: TypeCode
Stable dispatch identifier for this component type. Set by the
#[arkhe(type_code = N, ...)] attribute on the deriving struct.
Sourceconst SCHEMA_VERSION: u32
const SCHEMA_VERSION: u32
Version tag accompanying canonical bytes. Bumping invalidates older serialized payloads at decode time.
Provided Methods§
Sourcefn canonical_bytes(&self) -> Vec<u8> ⓘwhere
Self: Sized,
fn canonical_bytes(&self) -> Vec<u8> ⓘwhere
Self: Sized,
Postcard-canonical byte encoding. Default implementation uses
postcard::to_allocvec against the deriving type’s serde impl.
Sourcefn from_bytes(version: u32, bytes: &[u8]) -> Result<Box<Self>, DeserializeError>where
Self: Sized,
fn from_bytes(version: u32, bytes: &[u8]) -> Result<Box<Self>, DeserializeError>where
Self: Sized,
Inverse of canonical_bytes.
Returns DeserializeError::SchemaVersionMismatch if version
does not equal Component::SCHEMA_VERSION.
Sourcefn approx_size(&self) -> usizewhere
Self: Sized,
fn approx_size(&self) -> usizewhere
Self: Sized,
Approximate byte size — defaults to canonical_bytes().len().
Override only if a cheaper estimate is required.
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.