Skip to main content

SubscriberDef

Trait SubscriberDef 

Source
pub trait SubscriberDef: Sized {
    type Input;
    type Context;
    type Handler;
    type Source;

    // Required methods
    fn source(&self) -> Self::Source;
    fn into_handler(self) -> Self::Handler;

    // Provided methods
    fn description(&self) -> Option<&str> { ... }
    fn input_schema(&self) -> Option<String> { ... }
    fn message_name(&self) -> Option<&'static str> { ... }
    fn message_description(&self) -> Option<&'static str> { ... }
    fn workers(&self) -> Workers { ... }
    fn failure_policies(&self) -> FailurePolicies { ... }
}
Expand description

A handler definition produced by the #[subscriber] macro.

It bundles a typed Handler with the subscription Source it binds to, so BrokerScope::include can subscribe and wire decoding without the caller repeating anything. The source is a Name for #[subscriber("topic")], or a broker descriptor for #[subscriber(RedisStream::new(..))]. The generated type is itself the handler, so Handler is usually Self.

Required Associated Types§

Source

type Input

The decoded message type the handler consumes.

Source

type Context

The broker’s typed per-delivery context the handler reads by key (() when the handler names no context type).

Source

type Handler

The concrete handler type over Input and Context.

The handler bound is enforced where the def is mounted (against the app’s state type St), not on the trait: a handler that reads typed application state is Handler<Input, Context, St> only for its declared St, while one that ignores state is generic over it. Pinning a single state type here would reject both shapes.

Source

type Source

The subscription source this handler binds to. The bound to SubscriptionSource for the target broker is applied where the def is mounted, not on the trait, so a def can name any broker’s descriptor.

Required Methods§

Source

fn source(&self) -> Self::Source

Builds the subscription source (fresh each call).

Source

fn into_handler(self) -> Self::Handler

Consumes the definition, returning the handler.

Provided Methods§

Source

fn description(&self) -> Option<&str>

An optional human description (from the handler’s doc comment), for AsyncAPI.

Source

fn input_schema(&self) -> Option<String>

The input type’s serialized JSON Schema, when it implements [schemars::JsonSchema] and the asyncapi feature is on. The macro fills this in; the default omits it.

Source

fn message_name(&self) -> Option<&'static str>

The input type’s Message name, when it implements that trait. The macro fills this in; the default omits it.

Source

fn message_description(&self) -> Option<&'static str>

The input type’s Message description, when it implements that trait. The macro fills this in; the default omits it.

Source

fn workers(&self) -> Workers

The concurrency policy for this subscriber’s dispatch loop. The macro fills this in from the workers(..) argument; the default is sequential dispatch.

Source

fn failure_policies(&self) -> FailurePolicies

The failure policy for a handler panic and a decode failure. The macro fills this in from the on_failure(panic = .., decode = ..) argument; the default fails fast on a panic and drops on a decode failure.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§