pub trait SubscriptionSource<B: Broker> {
type Subscriber: Subscriber;
// Required methods
fn name(&self) -> &str;
fn subscribe(
self,
broker: &B,
) -> impl Future<Output = Result<Self::Subscriber, B::Error>> + Send;
}Expand description
A description of one subscription, resolved against a concrete broker at startup.
The runtime calls subscribe once, after Broker::connect, to obtain the live
Subscriber. The associated Subscriber type lives on the source rather
than the broker, so a single broker can offer several subscription kinds with different
subscriber types (for example Redis pub/sub versus streams).
§Examples
use ruststream::{Broker, SubscriptionSource};
async fn open<B, S>(source: S, broker: &B) -> Result<S::Subscriber, B::Error>
where
B: Broker,
S: SubscriptionSource<B>,
{
source.subscribe(broker).await
}Required Associated Types§
Sourcetype Subscriber: Subscriber
type Subscriber: Subscriber
The subscriber type this source opens.
Required Methods§
Sourcefn name(&self) -> &str
fn name(&self) -> &str
The name (subject / channel) this subscription binds to.
Used for handler metadata and AsyncAPI generation; it need not be the only routing
information the source carries.
Sourcefn subscribe(
self,
broker: &B,
) -> impl Future<Output = Result<Self::Subscriber, B::Error>> + Send
fn subscribe( self, broker: &B, ) -> impl Future<Output = Result<Self::Subscriber, B::Error>> + Send
Opens the subscription against broker. Called once, after Broker::connect.
§Errors
Returns Broker::Error when the broker rejects the subscription or the transport fails.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".