Skip to main content

OwningCodec

Trait OwningCodec 

Source
pub trait OwningCodec<E: ?Sized>: for<'a> Decode<E, Output<'a> = E> { }
Expand description

An owning codec: decode yields a fully-owned E that borrows nothing from the codec beyond the call.

This is the Decode analogue of serde’s DeserializeOwned — a name for the higher-ranked bound for<'a> Decode<E, Output<'a> = E>, so a generic caller writes C: OwningCodec<E> instead of spelling the for<'a> itself. The blanket impl covers every codec that satisfies the bound, so it is a transparent alias, never something to implement by hand.

Zero-copy codecs (rkyv, bytemuck), whose Output<'a> borrows (&'a E / &'a Archived<E>), deliberately do not satisfy it — code bounded on OwningCodec accepts only carry-away decoding, the same steer as DecodedStreamExt::decoded.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<C, E: ?Sized> OwningCodec<E> for C
where C: for<'a> Decode<E, Output<'a> = E>,