pub struct PubSubContext { /* private fields */ }Expand description
Per-delivery context for a Redis Pub/Sub delivery (RedisPubSubMessage).
Pub/Sub keeps no history, so there is nothing to reposition and no position to report: the fields are the delivery’s own channel and how it matched.
Implementations§
Source§impl PubSubContext
impl PubSubContext
Sourcepub fn new(channel: impl Into<String>, from_pattern: bool, pool: Pool) -> Self
pub fn new(channel: impl Into<String>, from_pattern: bool, pool: Pool) -> Self
Constructs a context directly from its native fields (mainly for tests).
§Examples
use std::error::Error;
use fred::clients::Pool;
use fred::types::config::Config;
use ruststream_fred::context::PubSubContext;
/// The region a fan-out delivery belongs to, read off the channel it arrived on.
fn region(cx: &PubSubContext) -> &str {
cx.channel().rsplit_once('.').map_or("", |(_, region)| region)
}
// An unconnected pool: `Pool::new` opens no socket.
let pool = Pool::new(Config::default(), None, None, None, 1)?;
let cx = PubSubContext::new("events.eu", true, pool);
assert_eq!(region(&cx), "eu");Sourcepub const fn pool(&self) -> &Pool
pub const fn pool(&self) -> &Pool
The broker’s connection pool, for a command whose answer the handler needs now.
Sourcepub fn channel(&self) -> &str
pub fn channel(&self) -> &str
The concrete channel this message arrived on (the matched channel, not the subscription glob, for a pattern subscription).
Sourcepub const fn from_pattern(&self) -> bool
pub const fn from_pattern(&self) -> bool
Whether the delivery matched through a PSUBSCRIBE pattern rather than an exact subscribe.
Trait Implementations§
Source§impl BuildContext<RedisPubSubMessage> for PubSubContext
impl BuildContext<RedisPubSubMessage> for PubSubContext
Source§fn build(msg: &RedisPubSubMessage) -> Self
fn build(msg: &RedisPubSubMessage) -> Self
Builds the context value by reading fields out of
msg.Source§impl Clone for PubSubContext
impl Clone for PubSubContext
Source§impl Debug for PubSubContext
impl Debug for PubSubContext
Source§impl Field<PubSubContext> for FredPool
impl Field<PubSubContext> for FredPool
Source§impl Field<PubSubContext> for Channel
impl Field<PubSubContext> for Channel
Source§impl Field<PubSubContext> for FromPattern
impl Field<PubSubContext> for FromPattern
Source§impl<State: Sync> FromContext<PubSubContext, State> for Ctx<FredPool>
Ctx<keys::FredPool> beside a Pub/Sub key: the handler’s context is PubSubContext there.
impl<State: Sync> FromContext<PubSubContext, State> for Ctx<FredPool>
Ctx<keys::FredPool> beside a Pub/Sub key: the handler’s context is PubSubContext there.
Source§type Rejection = !
type Rejection = !
The error returned when extraction fails. It is converted into a
HandlerOutcome (the
reflexive conversion makes HandlerOutcome itself a valid rejection, and Infallible
works for an extractor that never fails) and the delivery is settled by that outcome,
skipping the handler body.Source§fn from_context(
ctx: &mut Context<'_, PubSubContext, State>,
) -> impl Future<Output = Result<Self, Infallible>> + Send
fn from_context( ctx: &mut Context<'_, PubSubContext, State>, ) -> impl Future<Output = Result<Self, Infallible>> + Send
Resolves the value from the delivery context. The context is borrowed mutably so an
extractor may also read broker fields or take scratch a middleware left for it. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for PubSubContext
impl !UnwindSafe for PubSubContext
impl Freeze for PubSubContext
impl Send for PubSubContext
impl Sync for PubSubContext
impl Unpin for PubSubContext
impl UnsafeUnpin for PubSubContext
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<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