Skip to main content

InboxRow

Trait InboxRow 

Source
pub trait InboxRow: QueueRow {
    const SPEC: TableSpec<'static>;
}
Expand description

A struct that describes a queue table; #[derive(Inbox)] implements it.

The struct puts its table in one of two modes. In payload mode a #[field(payload)] field holds the message, and a codec decodes it for the handler (PayloadRow). In row mode the struct has no such field, and the handler takes the struct itself, &Row or &[Row] (see Row mode).

§Examples

use ruststream_sqlx::prelude::*;
use serde::Deserialize;
use sqlx::PgPool;

// The derive implements `InboxRow` for `SendEmail`: the table `app.email_jobs`, its id and
// its payload column.
#[derive(Inbox, sqlx::FromRow)]
#[inbox(table = "email_jobs", schema = "app")]
pub struct SendEmail {
    #[field(id)]
    job_id: i64,
    #[field(payload)]
    payload: Vec<u8>,
}

#[derive(Deserialize)]
struct Email {
    to: String,
}

#[subscriber(InboxQueue::<SendEmail>::new("emails"))]
async fn send(email: &Email) -> HandlerOutcome {
    tracing::info!(to = %email.to, "sending");
    HandlerOutcome::ack()
}

pub fn app(pool: PgPool) -> RustStream {
    RustStream::new(AppInfo::new("mailer", "0.1.0")).with_broker(SqlxBroker::new(pool), |b| {
        b.include(send);
    })
}

Required Associated Constants§

Source

const SPEC: TableSpec<'static>

The table the struct describes: its name, its columns and their roles, and the form its rows are claimed in.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<Row, Settings> InboxRow for Row
where Row: InboxTable<Table = InboxSpec<Settings>>, Settings: Declaration, Settings::Message: MessageAxis<Row>, Settings::Form: FormAxis, Settings::Opening: OpeningAxis,

Source§

const SPEC: TableSpec<'static>