pub struct NonZeroDuration(/* private fields */);Expand description
A Duration that is known not to be zero.
JetStreamSubject::pull_expires and JetStreamSubject::ack_wait take one. A fetch that
expires the instant it is issued turns the batch loop into a hot spin, so the zero is kept out
of the type instead of being caught when the subscription opens.
§Examples
use ruststream_nats::prelude::*;
use serde::Deserialize;
#[derive(Deserialize)]
struct Order {
amount: u64,
}
#[subscriber(
JetStreamSubject::new("orders.*", "ORDERS")
.durable("reconciler")
.ack_wait(NonZeroDuration::from_secs(nonzero!(60)))
.pull_expires(NonZeroDuration::from_millis(nonzero!(300)))
)]
async fn reconcile(orders: &[Order]) -> HandlerOutcome {
let total: u64 = orders.iter().map(|order| order.amount).sum();
tracing::info!(count = orders.len(), total, "reconciled");
HandlerOutcome::ack()
}
#[ruststream::app]
fn app() -> impl App {
RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(
NatsBroker::new("nats://localhost:4222"),
|b| {
b.include(reconcile.batch(nonzero!(50)));
},
)
}A literal is checked while the crate compiles, so a zero window does not build:
ⓘ
use ruststream::nonzero;
use ruststream_nats::NonZeroDuration;
let window = NonZeroDuration::from_millis(nonzero!(0));Implementations§
Source§impl NonZeroDuration
impl NonZeroDuration
Sourcepub const fn new(value: Duration) -> Option<Self>
pub const fn new(value: Duration) -> Option<Self>
Wraps value, or returns None when it is zero.
This is the entry for a duration that arrives at run time, from configuration or from a
calculation. A literal reads better through from_secs or
from_millis.
Sourcepub const fn from_secs(secs: NonZeroU64) -> Self
pub const fn from_secs(secs: NonZeroU64) -> Self
Builds a duration of secs seconds.
Sourcepub const fn from_millis(millis: NonZeroU64) -> Self
pub const fn from_millis(millis: NonZeroU64) -> Self
Builds a duration of millis milliseconds.
Trait Implementations§
Source§impl Clone for NonZeroDuration
impl Clone for NonZeroDuration
impl Copy for NonZeroDuration
Source§impl Debug for NonZeroDuration
impl Debug for NonZeroDuration
impl Eq for NonZeroDuration
Source§impl From<NonZeroDuration> for Duration
impl From<NonZeroDuration> for Duration
Source§fn from(value: NonZeroDuration) -> Self
fn from(value: NonZeroDuration) -> Self
Converts to this type from the input type.
Source§impl Hash for NonZeroDuration
impl Hash for NonZeroDuration
Source§impl Ord for NonZeroDuration
impl Ord for NonZeroDuration
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl PartialEq for NonZeroDuration
impl PartialEq for NonZeroDuration
Source§impl PartialOrd for NonZeroDuration
impl PartialOrd for NonZeroDuration
impl StructuralPartialEq for NonZeroDuration
Auto Trait Implementations§
impl Freeze for NonZeroDuration
impl RefUnwindSafe for NonZeroDuration
impl Send for NonZeroDuration
impl Sync for NonZeroDuration
impl Unpin for NonZeroDuration
impl UnsafeUnpin for NonZeroDuration
impl UnwindSafe for NonZeroDuration
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
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> 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