pub struct Extensions { /* private fields */ }Expand description
A per-delivery type-map: at most one value per type, scoped to a single delivery.
Unlike the app-level State (shared, set once at build), an Extensions map is created fresh
for each delivery and dropped when the handler returns, so one delivery’s values never leak into
the next. A broker contributes typed per-delivery data through
IncomingMessage::extensions (native delivery metadata,
a commit token, a reply-to handle) without going through the byte-only headers; middleware may
write entries for downstream handlers (via
Context::insert); and the values are reachable from the
publish path so a transactional publisher can read a broker-supplied commit token at commit
time.
§Examples
use ruststream::Extensions;
let mut ext = Extensions::new();
ext.insert(7u32);
assert_eq!(*ext.get::<u32>()?, 7);Implementations§
Source§impl Extensions
impl Extensions
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty map.
§Examples
use ruststream::Extensions;
let ext = Extensions::new();
assert!(ext.is_empty());Sourcepub fn insert<T: Any + Send + Sync>(&mut self, value: T)
pub fn insert<T: Any + Send + Sync>(&mut self, value: T)
Inserts value, replacing any previous value of the same type.
§Examples
use ruststream::Extensions;
let mut ext = Extensions::new();
ext.insert("first");
ext.insert("second");
assert_eq!(*ext.get::<&str>()?, "second");