Skip to main content

nonzero

Macro nonzero 

Source
macro_rules! nonzero {
    ($value:expr) => { ... };
}
Expand description

Builds a NonZero integer from a literal, rejecting zero at compile time.

The expansion is an inline const block, so nonzero!(0) fails the build instead of panicking at runtime, and the NonZero width is inferred from the call site - the same literal works for a batch size (NonZeroUsize) and any other NonZero parameter.

§Examples

use ruststream::memory::prelude::*;
use serde::Deserialize;

#[derive(Deserialize)]
struct Order {
    id: u64,
}

#[subscriber("orders")]
async fn settle(orders: &[Order]) -> HandlerOutcome {
    tracing::info!(count = orders.len(), "settled a batch");
    HandlerOutcome::ack()
}

fn app() -> RustStream {
    RustStream::new(AppInfo::new("orders", "0.1.0")).with_broker(MemoryBroker::new(), |b| {
        b.include(settle.batch(nonzero!(128)).workers(nonzero!(4)));
    })
}

Zero does not compile:

ⓘ
let _: core::num::NonZeroUsize = ruststream::nonzero!(0);