pub trait Discard<DB: Database>: InboxRow {
// Required method
fn discard(
conn: &mut DB::Connection,
id: &Self::Id,
) -> impl Future<Output = Result<(), Error>> + Send;
}Expand description
Drops a row: by default it deletes the row, or sets processed_at.
The service’s own drop takes the row out of what the claim selects, as an acknowledgement does.
§Examples
use std::time::Duration;
use ruststream_sqlx::{Discard, Inbox};
use sqlx::{PgConnection, Postgres};
#[derive(Inbox, sqlx::FromRow)]
#[inbox(table = "jobs", custom(discard))]
pub struct Job {
#[field(id)]
id: i64,
#[field(payload)]
payload: Vec<u8>,
}
impl Discard<Postgres> for Job {
async fn discard(
conn: &mut PgConnection,
id: &i64,
) -> Result<(), sqlx::Error> {
sqlx::query("DELETE FROM jobs WHERE id = $1")
.bind(id)
.execute(conn)
.await?;
Ok(())
}
}Required Methods§
Sourcefn discard(
conn: &mut DB::Connection,
id: &Self::Id,
) -> impl Future<Output = Result<(), Error>> + Send
fn discard( conn: &mut DB::Connection, id: &Self::Id, ) -> impl Future<Output = Result<(), Error>> + Send
Runs the discard event for the row id inside a transaction the crate commits: the claim’s, or in the lease form one that first confirms the row still holds the delivery’s lease.
§Errors
The database’s error; the transaction rolls back, and the row returns to the queue at once, or in the lease form once its lease runs out.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".