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
impl EncoderRegistry
Sourcepub fn register<T, F>(&mut self, payload_type: PayloadType, func: F)
pub fn register<T, F>(&mut self, payload_type: PayloadType, func: F)
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.
Sourcepub fn register_with_headers<T, F, H>(
&mut self,
payload_type: PayloadType,
func: F,
headers_fn: H,
)
pub fn register_with_headers<T, F, H>( &mut self, payload_type: PayloadType, func: F, headers_fn: H, )
Registers func as the encoder for T and headers_fn as the matching headers
extractor in one call.
Sourcepub fn register_encoder<T: 'static>(
&mut self,
payload_type: PayloadType,
encoder: Arc<dyn Encode>,
)
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.
Sourcepub fn register_headers<T, H>(&mut self, headers_fn: H)
pub fn register_headers<T, H>(&mut self, headers_fn: H)
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.
Sourcepub fn register_identity<T, F>(&mut self, identity_fn: F)
pub fn register_identity<T, F>(&mut self, identity_fn: F)
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.
Sourcepub fn encode<T: 'static>(
&self,
message: &T,
) -> Result<Option<(PayloadType, EncodedPayload)>, EncodeError>
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.
Sourcepub fn encode_any(
&self,
message: &dyn Any,
) -> Result<Option<(PayloadType, EncodedPayload)>, EncodeError>
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.
Sourcepub fn headers_for_any(&self, message: &dyn Any) -> Option<Headers>
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.
Sourcepub fn identity_for_any(&self, message: &dyn Any) -> Option<UUID4>
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
impl Clone for EncoderRegistry
Source§fn clone(&self) -> EncoderRegistry
fn clone(&self) -> EncoderRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EncoderRegistry
impl Debug for EncoderRegistry
Source§impl Default for EncoderRegistry
impl Default for EncoderRegistry
Source§fn default() -> EncoderRegistry
fn default() -> EncoderRegistry
Auto Trait Implementations§
impl !RefUnwindSafe for EncoderRegistry
impl !UnwindSafe for EncoderRegistry
impl Freeze for EncoderRegistry
impl Send for EncoderRegistry
impl Sync for EncoderRegistry
impl Unpin for EncoderRegistry
impl UnsafeUnpin for EncoderRegistry
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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