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§
Sourcetype In: Storage + ?Sized
type In: Storage + ?Sized
Input storage. Position-in-tree declaration via bb_ir::types::Storage.
Required Methods§
Sourcefn encode(
&self,
ctx: &mut RuntimeResourceRef<'_>,
input: &Self::In,
completion: CompletionHandle<Box<Self::Out>, Self::Error>,
) -> ContractResponse<Box<Self::Out>, Self::Error>
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.
Sourcefn decode(
&self,
ctx: &mut RuntimeResourceRef<'_>,
encoded: &Self::Out,
completion: CompletionHandle<Box<Self::In>, Self::Error>,
) -> ContractResponse<Box<Self::In>, Self::Error>
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§
Sourcefn train(
&mut self,
_ctx: &mut RuntimeResourceRef<'_>,
_samples: &[&Self::In],
_completion: CompletionHandle<(), Self::Error>,
) -> ContractResponse<(), Self::Error>
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".