pub struct Notifier { /* private fields */ }Expand description
Holds the configured channels and fans a notification out across them.
Bound in the container; resolve it, or reach it through the Notify
facade.
struct User(u64);
impl Notifiable for User {
fn notifiable_id(&self) -> String { self.0.to_string() }
fn notifiable_type(&self) -> &'static str { "User" }
fn route_for(&self, _: &str) -> Option<String> { Some(self.0.to_string()) }
}
struct Welcome;
impl Notification<User> for Welcome {
fn notification_name(&self) -> &'static str { "user.welcome" }
fn via(&self, _: &User) -> Channels { Channels::new().with::<MemoryChannel>() }
fn to_text(&self, _: &User) -> Option<String> { Some("hello".into()) }
}
let captured = Arc::new(MemoryChannel::new());
let notifier = Notifier::new().with_arc(Arc::clone(&captured));
notifier.send(&User(7), &Welcome).await?;
assert!(captured.sent_to("user.welcome", "7"));Implementations§
Source§impl Notifier
impl Notifier
Sourcepub fn new() -> Notifier
pub fn new() -> Notifier
A notifier with no channels.
Sending through it delivers nothing and says so per channel — see
Sent::NotRegistered.
Sourcepub fn with_arc<C>(self, channel: Arc<C>) -> Notifierwhere
C: Channel,
pub fn with_arc<C>(self, channel: Arc<C>) -> Notifierwhere
C: Channel,
Register an already-shared channel.
For one a test holds a handle to — a MemoryChannel
it will assert on.
Sourcepub fn channel_names(&self) -> Vec<&'static str>
pub fn channel_names(&self) -> Vec<&'static str>
The registered channels’ names, in registration order.
Sourcepub async fn send<N, T>(
&self,
to: &N,
notification: &T,
) -> Result<Receipt, Error>
pub async fn send<N, T>( &self, to: &N, notification: &T, ) -> Result<Receipt, Error>
Send notification to to.
Every channel the notification selected is tried. A channel failing does not stop the others — an SMTP outage should not also cost the database row that puts the notification in the recipient’s bell menu.
The Receipt says what happened on each. Ok unless every channel
failed; call Receipt::into_result to make “nothing got through” an
error at the call site.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Notifier
impl !UnwindSafe for Notifier
impl Freeze for Notifier
impl Send for Notifier
impl Sync for Notifier
impl Unpin for Notifier
impl UnsafeUnpin for Notifier
Blanket Implementations§
impl<T> Actor for T
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Event for T
impl<T> Event for T
Source§fn event_name() -> &'static strwhere
Self: Sized,
fn event_name() -> &'static strwhere
Self: Sized,
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> ⓘ
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> ⓘ
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