Skip to main content

Component

Trait Component 

Source
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§

Source

const TYPE_CODE: TypeCode

Stable dispatch identifier for this component type. Set by the #[arkhe(type_code = N, ...)] attribute on the deriving struct.

Source

const SCHEMA_VERSION: u32

Version tag accompanying canonical bytes. Bumping invalidates older serialized payloads at decode time.

Provided Methods§

Source

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.

Source

fn from_bytes(version: u32, bytes: &[u8]) -> Result<Box<Self>, DeserializeError>
where Self: Sized,

Source

fn approx_size(&self) -> usize
where 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.

Implementors§