pub struct ValueBytesCodecDescriptor { /* private fields */ }Expand description
An immutable, safely erased bidirectional bytes codec for one value type.
Each operation creates a fresh default codec; no codec state is retained. Type identities are process-local and names are diagnostic, not stable IDs.
§Examples
use core::convert::Infallible;
use qubit_codec::ValueBytesCodecDescriptor;
use qubit_codec::ValueDecoder;
use qubit_codec::ValueEncoder;
#[derive(Default)]
struct Bytes;
impl ValueEncoder<Vec<u8>> for Bytes {
type Error = Infallible;
type Output = Vec<u8>;
fn encode(&mut self, value: &Vec<u8>) -> Result<Vec<u8>, Infallible> {
Ok(value.clone())
}
}
impl ValueDecoder<[u8]> for Bytes {
type Error = Infallible;
type Output = Vec<u8>;
fn decode(&mut self, input: &[u8]) -> Result<Vec<u8>, Infallible> {
Ok(input.to_vec())
}
}
let descriptor = ValueBytesCodecDescriptor::of::<Bytes, Vec<u8>>();
let bytes = descriptor.encode(&vec![1_u8, 2]).unwrap();
let decoded = descriptor.decode(&bytes).unwrap();
assert_eq!(*decoded.downcast::<Vec<u8>>().unwrap(), vec![1, 2]);Implementations§
Source§impl ValueBytesCodecDescriptor
impl ValueBytesCodecDescriptor
Sourcepub const fn of<C, V>() -> Selfwhere
C: Default + ValueEncoder<V, Output = Vec<u8>> + ValueDecoder<[u8], Output = V> + 'static,
<C as ValueEncoder<V>>::Error: Error + Send + Sync + 'static,
<C as ValueDecoder<[u8]>>::Error: Error + Send + Sync + 'static,
V: 'static,
pub const fn of<C, V>() -> Selfwhere
C: Default + ValueEncoder<V, Output = Vec<u8>> + ValueDecoder<[u8], Output = V> + 'static,
<C as ValueEncoder<V>>::Error: Error + Send + Sync + 'static,
<C as ValueDecoder<[u8]>>::Error: Error + Send + Sync + 'static,
V: 'static,
Creates a descriptor for codec C and value type V.
Both codec error types must implement Send + Sync so execution errors
can retain their source across thread boundaries. The codec and value
types themselves need not implement these traits; V only needs to be
'static because decoded values are returned through Any.
§Type Parameters
C: Default-constructible bytes encoder/decoder with owned errors.V: Owned value type accepted and produced byC.
§Returns
Returns immutable function metadata without constructing a codec.
Sourcepub fn codec_type_id(&self) -> TypeId
pub fn codec_type_id(&self) -> TypeId
Sourcepub fn codec_type_name(&self) -> &'static str
pub fn codec_type_name(&self) -> &'static str
Sourcepub fn value_type_id(&self) -> TypeId
pub fn value_type_id(&self) -> TypeId
Sourcepub fn value_type_name(&self) -> &'static str
pub fn value_type_name(&self) -> &'static str
Trait Implementations§
Source§impl Clone for ValueBytesCodecDescriptor
impl Clone for ValueBytesCodecDescriptor
impl Copy for ValueBytesCodecDescriptor
Auto Trait Implementations§
impl Forget for ValueBytesCodecDescriptor
impl Freeze for ValueBytesCodecDescriptor
impl RefUnwindSafe for ValueBytesCodecDescriptor
impl Send for ValueBytesCodecDescriptor
impl Sync for ValueBytesCodecDescriptor
impl Unpin for ValueBytesCodecDescriptor
impl UnsafeUnpin for ValueBytesCodecDescriptor
impl UnwindSafe for ValueBytesCodecDescriptor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more