Skip to main content

Extensions

Struct Extensions 

Source
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

Source

pub fn new() -> Self

Creates an empty map.

§Examples
use ruststream::Extensions;

let ext = Extensions::new();
assert!(ext.is_empty());
Source

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");
Source

pub fn get<T: Any + Send + Sync>(&self) -> Option<&T>

Returns the stored value of type T, if any.

§Examples
use ruststream::Extensions;

let mut ext = Extensions::new();
ext.insert(42u64);
assert_eq!(ext.get::<u64>(), Some(&42));
assert_eq!(ext.get::<i8>(), None);
Source

pub fn is_empty(&self) -> bool

Whether the map holds no entries.

§Examples
use ruststream::Extensions;

let mut ext = Extensions::new();
assert!(ext.is_empty());
ext.insert(1u8);
assert!(!ext.is_empty());

Trait Implementations§

Source§

impl Debug for Extensions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Extensions

Source§

fn default() -> Extensions

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more