Skip to main content

EncoderRegistry

Struct EncoderRegistry 

Source
pub struct EncoderRegistry { /* private fields */ }
Expand description

Allow-list of capturable Rust message types and their encoders.

Registration is keyed by std::any::TypeId; the adapter dispatches by TypeId so callers can capture a typed message without naming the encoder concretely. A type registered twice replaces the prior entry: the SPEC’s encoder rules require one canonical mapping per Rust type, and the registry would otherwise hide the conflict.

Implementations§

Source§

impl EncoderRegistry

Source

pub fn new() -> Self

Creates a new empty registry.

Source

pub fn register<T, F>(&mut self, payload_type: PayloadType, func: F)
where T: 'static, F: Fn(&T) -> Result<EncodedPayload, EncodeError> + Send + Sync + 'static,

Registers func as the encoder for T and stamps every captured entry with payload_type. Captures yield Headers::empty until Self::register_headers records an extractor for T.

Replaces any encoder previously registered for T; capture flows hold the registry as Arc<EncoderRegistry> so registration must happen before the adapter is constructed.

Source

pub fn register_with_headers<T, F, H>( &mut self, payload_type: PayloadType, func: F, headers_fn: H, )
where T: 'static, F: Fn(&T) -> Result<EncodedPayload, EncodeError> + Send + Sync + 'static, H: Fn(&T) -> Headers + Send + Sync + 'static,

Registers func as the encoder for T and headers_fn as the matching headers extractor in one call.

Source

pub fn register_encoder<T: 'static>( &mut self, payload_type: PayloadType, encoder: Arc<dyn Encode>, )

Registers an already-built Encode implementer for T. Captures yield Headers::empty until Self::register_headers records an extractor.

Useful when the encoder owns state (e.g., a schema cache) the closure form cannot express ergonomically.

Source

pub fn register_headers<T, H>(&mut self, headers_fn: H)
where T: 'static, H: Fn(&T) -> Headers + Send + Sync + 'static,

Registers headers_fn as the headers extractor for T.

Call after Self::register when the encoder is preregistered through a shared helper but the call site wants a typed headers extractor. Replaces any prior extractor for T. Returns silently when T has no encoder registered: callers that care about the contract should rely on Self::contains.

Source

pub fn register_identity<T, F>(&mut self, identity_fn: F)
where T: 'static, F: Fn(&T) -> Option<UUID4> + Send + Sync + 'static,

Registers identity_fn as the identity extractor for T.

Call after Self::register. Replaces any prior extractor for T. Returns silently when T has no encoder registered: callers that care about the contract should rely on Self::contains.

Source

pub fn len(&self) -> usize

Returns the number of registered encoders.

Source

pub fn is_empty(&self) -> bool

Returns whether the registry is empty.

Source

pub fn contains<T: 'static>(&self) -> bool

Returns whether an encoder is registered for T.

Source

pub fn encode<T: 'static>( &self, message: &T, ) -> Result<Option<(PayloadType, EncodedPayload)>, EncodeError>

Encodes message if a typed encoder is registered for T.

Returns Ok(None) when no encoder is registered for T so the adapter can drop the message at the dispatch boundary without surfacing it as an error: the allow-list is the source of truth for the captured surface, and out-of-list messages are non-state-affecting by definition.

§Errors

Returns the encoder’s EncodeError when an encoder is registered but rejects the message.

Source

pub fn encode_any( &self, message: &dyn Any, ) -> Result<Option<(PayloadType, EncodedPayload)>, EncodeError>

Encodes a type-erased message if an encoder is registered for the concrete type.

Mirror of Self::encode for &dyn Any callers; the bus tap reaches the capture path through this entry point because dispatch returns a &dyn Any and the static type is not in scope.

§Errors

Returns the encoder’s EncodeError when an encoder is registered for the concrete type but rejects the message.

Source

pub fn headers_for_any(&self, message: &dyn Any) -> Option<Headers>

Returns the headers carried by message if a registration exists for its concrete type. Returns None when no encoder is registered: the adapter then drops the message without further work.

Source

pub fn identity_for_any(&self, message: &dyn Any) -> Option<UUID4>

Returns the logical identity carried by message if its registration has an identity extractor. Returns None when the type is unregistered or carries no extractor; the adapter then captures per dispatch.

Trait Implementations§

Source§

impl Clone for EncoderRegistry

Source§

fn clone(&self) -> EncoderRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EncoderRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EncoderRegistry

Source§

fn default() -> EncoderRegistry

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Ungil for T
where T: Send,

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more