#[non_exhaustive]pub enum NamedTime {
Chrono(DateTime<Utc>),
Time(OffsetDateTime),
}Expand description
A time a by-name subscription binds, in the type its column holds: the current time, a delayed retry’s, or in the lease form a lease’s expiry.
A dialect binds it in ByName::bind_time. Each variant comes with
the feature of its time type, so a match keeps a wildcard arm.
§Examples
use ruststream::HeaderMap;
use ruststream_sqlx::prelude::*;
use ruststream_sqlx::{BuiltIn, ByName, NamedTime};
use serde::Deserialize;
use sqlx::error::BoxDynError;
use sqlx::postgres::{PgArguments, PgValueRef};
use sqlx::{Arguments, PgPool, Postgres};
/// A dialect of the service's own over Postgres, whose tables keep `chrono` times.
#[derive(Debug)]
pub struct Audited;
impl ByName<Postgres> for Audited {
fn headers(value: PgValueRef<'_>) -> Result<HeaderMap, BoxDynError> {
<BuiltIn<Postgres> as ByName<Postgres>>::headers(value)
}
fn bind_time(arguments: &mut PgArguments, time: NamedTime) -> Result<(), sqlx::Error> {
match time {
NamedTime::Chrono(at) => arguments.add(at).map_err(sqlx::Error::Encode),
_ => Err(sqlx::Error::Configuration("these tables keep `chrono` times".into())),
}
}
}
#[derive(Inbox, sqlx::FromRow)]
#[inbox(table = "email_jobs")]
pub struct SendEmail {
#[field(id, generated)]
job_id: i64,
#[field(group)]
name: String,
#[field(payload)]
payload: Vec<u8>,
}
#[derive(Deserialize)]
struct Email {
to: String,
}
#[subscriber("emails")]
async fn send(email: &Email) -> HandlerOutcome {
tracing::info!(to = %email.to, "sending");
HandlerOutcome::ack()
}
pub fn app(pool: PgPool) -> RustStream {
let broker = SqlxBroker::with_dialect(pool, Audited).route::<SendEmail>("emails");
RustStream::new(AppInfo::new("mailer", "0.1.0")).with_broker(broker, |b| {
b.include(send);
})
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Trait Implementations§
impl Copy for NamedTime
impl Eq for NamedTime
impl StructuralPartialEq for NamedTime
Auto Trait Implementations§
impl Freeze for NamedTime
impl RefUnwindSafe for NamedTime
impl Send for NamedTime
impl Sync for NamedTime
impl Unpin for NamedTime
impl UnsafeUnpin for NamedTime
impl UnwindSafe for NamedTime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more