Skip to main content

Codec

Trait Codec 

Source
pub trait Codec: Send + Sync {
    type In: Storage + ?Sized;
    type Out: Storage + ?Sized;
    type Error: Error + Display + Send + Sync + 'static;

    // Required methods
    fn encode(
        &self,
        ctx: &mut RuntimeResourceRef<'_>,
        input: &Self::In,
        completion: CompletionHandle<Box<Self::Out>, Self::Error>,
    ) -> ContractResponse<Box<Self::Out>, Self::Error>;
    fn decode(
        &self,
        ctx: &mut RuntimeResourceRef<'_>,
        encoded: &Self::Out,
        completion: CompletionHandle<Box<Self::In>, Self::Error>,
    ) -> ContractResponse<Box<Self::In>, Self::Error>;

    // Provided method
    fn train(
        &mut self,
        _ctx: &mut RuntimeResourceRef<'_>,
        _samples: &[&Self::In],
        _completion: CompletionHandle<(), Self::Error>,
    ) -> ContractResponse<(), Self::Error> { ... }
}
Expand description

User-facing Contract trait for a typed in/out storage codec.

Required Associated Types§

Source

type In: Storage + ?Sized

Input storage. Position-in-tree declaration via bb_ir::types::Storage.

Source

type Out: Storage + ?Sized

Output storage. Different position in the tree from In (otherwise the codec is identity and the author should remove it).

Source

type Error: Error + Display + Send + Sync + 'static

Library-maker-defined error type.

Required Methods§

Source

fn encode( &self, ctx: &mut RuntimeResourceRef<'_>, input: &Self::In, completion: CompletionHandle<Box<Self::Out>, Self::Error>, ) -> ContractResponse<Box<Self::Out>, Self::Error>

In → Out. ctx is the per-dispatch runtime surface; impls reach their declared #[depends(...)] siblings through RuntimeResourceRef::dependency.

Source

fn decode( &self, ctx: &mut RuntimeResourceRef<'_>, encoded: &Self::Out, completion: CompletionHandle<Box<Self::In>, Self::Error>, ) -> ContractResponse<Box<Self::In>, Self::Error>

Out → In. Lossy codecs implement the best-effort inverse. ctx is the per-dispatch runtime surface; impls reach their declared #[depends(...)] siblings through RuntimeResourceRef::dependency.

Provided Methods§

Source

fn train( &mut self, _ctx: &mut RuntimeResourceRef<'_>, _samples: &[&Self::In], _completion: CompletionHandle<(), Self::Error>, ) -> ContractResponse<(), Self::Error>

Optional training pass — quantizers need scale/zero-point calibration, PQ codebooks need k-means, plain dtype casts (f32 ↔ f16) skip this. Default returns Now(Ok(())).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§