Trait CratestackCodec
pub trait CratestackCodec:
Clone
+ Send
+ Sync
+ 'static {
const CONTENT_TYPE: &'static str;
// Required methods
fn encode<T>(&self, value: &T) -> Result<Vec<u8>, CratestackError>
where T: Serialize + ?Sized;
fn decode<T>(&self, bytes: &[u8]) -> Result<T, CratestackError>
where T: for<'de> Deserialize<'de>;
// Provided method
fn encode_into<T>(
&self,
value: &T,
out: &mut Vec<u8>,
) -> Result<(), CratestackError>
where T: Serialize + ?Sized { ... }
}Required Associated Constants§
const CONTENT_TYPE: &'static str
Required Methods§
fn encode<T>(&self, value: &T) -> Result<Vec<u8>, CratestackError>
fn decode<T>(&self, bytes: &[u8]) -> Result<T, CratestackError>where
T: for<'de> Deserialize<'de>,
Provided Methods§
fn encode_into<T>(
&self,
value: &T,
out: &mut Vec<u8>,
) -> Result<(), CratestackError>
fn encode_into<T>( &self, value: &T, out: &mut Vec<u8>, ) -> Result<(), CratestackError>
Append the encoding of value to out, leaving what out already
holds untouched. On success out[old_len..] is byte for byte what
encode returns.
This is the hook that lets a signing envelope encode straight into
its output buffer (ADR 0006 §1, “the sealer encodes straight into
the COSE buffer”; maintainer decision on cratestack#1005) instead of
encoding into a Vec of its own and copying it in. See
CratestackEnvelope::seal_value.
Provided, so adding it broke no codec: the default encodes and then
copies once, which is correct but is exactly the copy the hook exists
to avoid. A codec whose serializer can write into a Vec should
override it (CborCodec and JsonCodec do). On error an override
should leave out at its old length; the default always does.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".