pub struct BoxedCodec(/* private fields */);Expand description
A type-erased Codec that wraps any concrete codec behind a single type.
BoxedCodec removes the need for generic parameters when storing or
passing codecs across pipeline stages that support multiple encodings
(JSON, CloudEvents, Avro, …) without a shared enum.
§Construction
use rustcdc::codec::{BoxedCodec, Codec, JsonCodec};
// Via the .boxed() convenience method (preferred):
let codec: BoxedCodec = JsonCodec::default().boxed();
// Or explicitly:
let codec = BoxedCodec::new(JsonCodec::default());Implementations§
Source§impl BoxedCodec
impl BoxedCodec
Sourcepub fn new<C: Codec + 'static>(codec: C) -> Self
pub fn new<C: Codec + 'static>(codec: C) -> Self
Wrap any Codec implementation in a type-erased BoxedCodec.
Prefer Codec::boxed for ergonomic construction.
Trait Implementations§
Source§impl Codec for BoxedCodec
impl Codec for BoxedCodec
Source§fn encode(&self, event: &Event) -> Result<CodecOutput>
fn encode(&self, event: &Event) -> Result<CodecOutput>
Encode the event into a key + value pair.
Source§fn content_type(&self) -> &'static str
fn content_type(&self) -> &'static str
The MIME content type for every successful
value byte sequence.Source§fn boxed(self) -> BoxedCodecwhere
Self: Sized + 'static,
fn boxed(self) -> BoxedCodecwhere
Self: Sized + 'static,
Auto Trait Implementations§
impl !RefUnwindSafe for BoxedCodec
impl !UnwindSafe for BoxedCodec
impl Freeze for BoxedCodec
impl Send for BoxedCodec
impl Sync for BoxedCodec
impl Unpin for BoxedCodec
impl UnsafeUnpin for BoxedCodec
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