Skip to main content

Bindable

Trait Bindable 

Source
pub trait Bindable: Publisher + Named { }
Expand description

A publisher of this crate, which pipeline.bind(out) can bind to a delivery’s round.

Implemented by every publisher this crate’s policies pair into, and by nothing else: a publisher of another broker publishes through its own connection, which no round of this one can carry. A handler bounds its slot with it, Out(out): Out<impl Bindable>, to bind it.

§Examples

use ruststream_fred::stream::prelude::*;
use serde::Serialize;
#[derive(Serialize, Outgoing)]
#[outgoing(name = "audit")]
struct Audit {
    id: u64,
}

/// The audit entry leaves with the delivery's acknowledgement, and not without it.
#[subscriber(RedisStream::new("orders").group("workers"))]
async fn record(
    order: &Order,
    Ctx(pipeline): Ctx<keys::Pipeline>,
    Out(out): Out<impl Bindable>,
) -> HandlerOutcome {
    let out = pipeline.bind(out);
    if out.message(&Audit { id: order.id }).publish().await.is_err() {
        return HandlerOutcome::retry();
    }
    HandlerOutcome::ack()
}

fn app() -> RustStream {
    RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(
        RedisBroker::standalone("redis://localhost:6379"),
        |b| {
            b.include(record.pipeline()).out(DefaultSlot, Publish).build();
        },
    )
}

A publisher of another transport has no round to join, so binding one does not compile:

ⓘ
use std::convert::Infallible;

use ruststream::{Lend, OutgoingMessage, Publisher};
use ruststream_fred::pipeline::Bindable;

struct Elsewhere;

impl Publisher for Elsewhere {
    type Payload = Lend;
    type Error = Infallible;
    type Options = ();

    async fn publish(
        &self,
        _msg: OutgoingMessage<'_, &[u8]>,
        _options: Option<&()>,
    ) -> Result<(), Infallible> {
        Ok(())
    }
}

fn bindable<P: Bindable>() {}

bindable::<Elsewhere>();

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<T: Publisher + Named> Bindable for T