pub trait JsonCodec<T>: Send + Sync {
// Required methods
fn encode(&self, value: &T) -> Option<Value>;
fn decode(&self, value: &Value) -> Option<T>;
// Provided methods
fn encode_to_vec(&self, value: &T) -> Option<Vec<u8>> { ... }
fn decode_slice(&self, bytes: &[u8]) -> Option<T> { ... }
}Expand description
Type-erased JSON codec for one record type.
Stored as Arc<dyn JsonCodec<T>> inside TypedRecord<T, R>, where the
blanket AnyRecord impl cannot carry a T: RemoteSerialize bound (it must
also cover non-serializable record types). T is fixed per record, so the
trait is object-safe.
Required Methods§
Provided Methods§
Sourcefn encode_to_vec(&self, value: &T) -> Option<Vec<u8>>
fn encode_to_vec(&self, value: &T) -> Option<Vec<u8>>
Encode a typed value into owned JSON bytes.
Defaulted through encode so existing custom codecs
remain source-compatible and retain their exact JSON-tree semantics.
Sourcefn decode_slice(&self, bytes: &[u8]) -> Option<T>
fn decode_slice(&self, bytes: &[u8]) -> Option<T>
Decode one complete JSON value from a byte slice.
Defaulted through decode so existing custom codecs
remain source-compatible.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".