pub struct EncoderCodec<E> { /* private fields */ }Expand description
A Codec adapter that wraps any EventEncoder.
EncoderCodec calls EventEncoder::encode_key for the key and
EventEncoder::encode for the value. It is the canonical bridge between the
lower-level EventEncoder trait and the higher-level Codec trait.
§Example
use rustcdc::codec::{Codec, EncoderCodec, JsonEncoder};
use rustcdc::{Event, Operation, EVENT_ENVELOPE_VERSION};
use serde_json::json;
let codec = EncoderCodec::new(JsonEncoder);
let event = Event {
after: Some(json!({"id": 1})),
op: Operation::Insert,
primary_key: Some(vec!["id".into()]),
..Event::default()
};
let out = codec.encode(&event).unwrap();
assert_eq!(out.content_type, "application/json");
assert!(out.key.is_some());Implementations§
Source§impl<E: EventEncoder> EncoderCodec<E>
impl<E: EventEncoder> EncoderCodec<E>
Trait Implementations§
Source§impl<E: Clone> Clone for EncoderCodec<E>
impl<E: Clone> Clone for EncoderCodec<E>
Source§fn clone(&self) -> EncoderCodec<E>
fn clone(&self) -> EncoderCodec<E>
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<E: EventEncoder> Codec for EncoderCodec<E>
impl<E: EventEncoder> Codec for EncoderCodec<E>
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,
Source§impl<E: Debug> Debug for EncoderCodec<E>
impl<E: Debug> Debug for EncoderCodec<E>
Source§impl<E: Default> Default for EncoderCodec<E>
impl<E: Default> Default for EncoderCodec<E>
Source§fn default() -> EncoderCodec<E>
fn default() -> EncoderCodec<E>
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl<E> Freeze for EncoderCodec<E>where
E: Freeze,
impl<E> RefUnwindSafe for EncoderCodec<E>where
E: RefUnwindSafe,
impl<E> Send for EncoderCodec<E>where
E: Send,
impl<E> Sync for EncoderCodec<E>where
E: Sync,
impl<E> Unpin for EncoderCodec<E>where
E: Unpin,
impl<E> UnsafeUnpin for EncoderCodec<E>where
E: UnsafeUnpin,
impl<E> UnwindSafe for EncoderCodec<E>where
E: UnwindSafe,
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