pub struct Signal<T>{ /* private fields */ }core and non-WebAssembly only.Expand description
A signal that can dispatch events to connected receivers
Implementations§
Source§impl<T> Signal<T>
impl<T> Signal<T>
Sourcepub fn new(name: SignalName) -> Signal<T>
Available on crate feature signals only.
pub fn new(name: SignalName) -> Signal<T>
signals only.Create a new signal with a type-safe name
§Examples
use reinhardt_core::signals::{Signal, SignalName};
// Use built-in signal names
let signal = Signal::<String>::new(SignalName::PRE_SAVE);
// Use custom signal names
let custom = Signal::<String>::new(SignalName::custom("my_signal"));Sourcepub fn metrics(&self) -> SignalMetrics
Available on crate feature signals only.
pub fn metrics(&self) -> SignalMetrics
signals only.Get the current metrics for this signal
Sourcepub fn reset_metrics(&self)
Available on crate feature signals only.
pub fn reset_metrics(&self)
signals only.Reset metrics for this signal
Sourcepub fn add_middleware<M>(&self, middleware: M)where
M: SignalMiddleware<T> + 'static,
Available on crate feature signals only.
pub fn add_middleware<M>(&self, middleware: M)where
M: SignalMiddleware<T> + 'static,
signals only.Add middleware to this signal
Sourcepub fn context(&self) -> &SignalContext
Available on crate feature signals only.
pub fn context(&self) -> &SignalContext
signals only.Get the signal context
Sourcepub fn connect_with_options<F, Fut>(
&self,
receiver: F,
sender_type_id: Option<TypeId>,
dispatch_uid: Option<String>,
priority: i32,
)
Available on crate feature signals only.
pub fn connect_with_options<F, Fut>( &self, receiver: F, sender_type_id: Option<TypeId>, dispatch_uid: Option<String>, priority: i32, )
signals only.Connect a receiver function to this signal with full options
§Arguments
receiver- The receiver function to connectsender_type_id- Optional TypeId to filter by sender typedispatch_uid- Optional unique identifier to prevent duplicate registrationpriority- Execution priority (higher values execute first, default: 0)
Sourcepub fn connect_with_full_options<F, Fut, P>(
&self,
receiver: F,
sender_type_id: Option<TypeId>,
dispatch_uid: Option<String>,
priority: i32,
predicate: Option<P>,
)
Available on crate feature signals only.
pub fn connect_with_full_options<F, Fut, P>( &self, receiver: F, sender_type_id: Option<TypeId>, dispatch_uid: Option<String>, priority: i32, predicate: Option<P>, )
signals only.Connect a receiver with all available options including predicate
§Arguments
receiver- The receiver function to connectsender_type_id- Optional TypeId to filter by sender typedispatch_uid- Optional unique identifier to prevent duplicate registrationpriority- Execution priority (higher values execute first, default: 0)predicate- Optional condition that must be true for receiver to execute
Sourcepub fn connect<F, Fut>(&self, receiver: F)
Available on crate feature signals only.
pub fn connect<F, Fut>(&self, receiver: F)
signals only.Connect a receiver function to this signal (simple version)
Sourcepub fn connect_with_priority<F, Fut>(&self, receiver: F, priority: i32)
Available on crate feature signals only.
pub fn connect_with_priority<F, Fut>(&self, receiver: F, priority: i32)
signals only.Connect a receiver with priority
Sourcepub fn chain(&self, next: &Signal<T>)where
T: Clone,
Available on crate feature signals only.
pub fn chain(&self, next: &Signal<T>)where
T: Clone,
signals only.Chain this signal to another signal When this signal is sent, it will also trigger the chained signal
§Example
let signal_a = Signal::<User>::new(SignalName::custom("user_created"));
let signal_b = Signal::<User>::new(SignalName::custom("user_notified"));
signal_a.chain(&signal_b);
// Now sending signal_a will also trigger signal_b
signal_a.send(user).await?;Sourcepub fn chain_with<U, F>(&self, next: &Signal<U>, transform: F)
Available on crate feature signals only.
pub fn chain_with<U, F>(&self, next: &Signal<U>, transform: F)
signals only.Chain this signal to another signal with transformation Allows transforming the instance before passing to the next signal
§Example
signal_a.chain_with(&signal_b, |user| {
// Transform User to NotificationPayload
NotificationPayload::from(user)
});Sourcepub fn merge(signals: Vec<&Signal<T>>) -> Signal<T>where
T: Clone,
Available on crate feature signals only.
pub fn merge(signals: Vec<&Signal<T>>) -> Signal<T>where
T: Clone,
signals only.Merge multiple signals into one Returns a new signal that triggers when any of the source signals trigger
§Example
let merged = Signal::merge(vec![&signal_a, &signal_b, &signal_c]);
merged.connect(|instance| async move {
println!("Any of the three signals was triggered!");
Ok(())
});Sourcepub fn filter<P>(&self, predicate: P) -> Signal<T>
Available on crate feature signals only.
pub fn filter<P>(&self, predicate: P) -> Signal<T>
signals only.Filter signal emissions based on a predicate Returns a new signal that only triggers when the predicate returns true
§Example
let admin_only = user_signal.filter(|user| user.is_admin);
admin_only.connect(|admin_user| async move {
println!("Admin user action!");
Ok(())
});Sourcepub fn map<U, F>(&self, transform: F) -> Signal<U>
Available on crate feature signals only.
pub fn map<U, F>(&self, transform: F) -> Signal<U>
signals only.Transform signal values Returns a new signal with transformed values
§Example
let user_ids = user_signal.map(|user| user.id);
user_ids.connect(|id| async move {
println!("User ID: {}", id);
Ok(())
});Sourcepub fn connect_if<F, Fut, P>(&self, receiver: F, predicate: P)
Available on crate feature signals only.
pub fn connect_if<F, Fut, P>(&self, receiver: F, predicate: P)
signals only.Connect a receiver with a predicate condition
The receiver will only execute if the predicate returns true for the instance
Sourcepub fn disconnect(&self, dispatch_uid: &str) -> bool
Available on crate feature signals only.
pub fn disconnect(&self, dispatch_uid: &str) -> bool
signals only.Disconnect a receiver by dispatch_uid
Sourcepub async fn send_with_sender(
&self,
instance: T,
sender_type_id: Option<TypeId>,
) -> Result<(), SignalError>
Available on crate feature signals only.
pub async fn send_with_sender( &self, instance: T, sender_type_id: Option<TypeId>, ) -> Result<(), SignalError>
signals only.Send signal to all connected receivers
§Arguments
instance- The instance to sendsender_type_id- Optional TypeId of the sender for filtering
Sourcepub async fn send(&self, instance: T) -> Result<(), SignalError>
Available on crate feature signals only.
pub async fn send(&self, instance: T) -> Result<(), SignalError>
signals only.Send signal to all connected receivers (simple version)
Sourcepub async fn send_robust(
&self,
instance: T,
sender_type_id: Option<TypeId>,
) -> Vec<Result<(), SignalError>>
Available on crate feature signals only.
pub async fn send_robust( &self, instance: T, sender_type_id: Option<TypeId>, ) -> Vec<Result<(), SignalError>>
signals only.Send signal robustly, catching errors
Sourcepub fn send_async(&self, instance: T)
Available on crate feature signals only.
pub fn send_async(&self, instance: T)
signals only.Send signal asynchronously (fire and forget)
Sourcepub fn receiver_count(&self) -> usize
Available on crate feature signals only.
pub fn receiver_count(&self) -> usize
signals only.Get number of connected receivers
Sourcepub fn disconnect_all(&self)
Available on crate feature signals only.
pub fn disconnect_all(&self)
signals only.Clear all receivers
Trait Implementations§
Source§impl<T> AsyncSignalDispatcher<T> for Signal<T>
impl<T> AsyncSignalDispatcher<T> for Signal<T>
Source§fn send<'life0, 'async_trait>(
&'life0 self,
instance: T,
) -> Pin<Box<dyn Future<Output = Result<(), SignalError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Signal<T>: 'async_trait,
fn send<'life0, 'async_trait>(
&'life0 self,
instance: T,
) -> Pin<Box<dyn Future<Output = Result<(), SignalError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Signal<T>: 'async_trait,
Source§impl<T> InjectableSignal<T> for Signal<T>
impl<T> InjectableSignal<T> for Signal<T>
Source§fn connect_with_context<F, Fut>(&self, receiver: F)where
F: Fn(Arc<T>, ReceiverContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<(), SignalError>> + Send + 'static,
fn connect_with_context<F, Fut>(&self, receiver: F)where
F: Fn(Arc<T>, ReceiverContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<(), SignalError>> + Send + 'static,
Source§impl<T> SignalDispatcher<T> for Signal<T>
impl<T> SignalDispatcher<T> for Signal<T>
Source§fn receiver_count(&self) -> usize
fn receiver_count(&self) -> usize
Source§fn disconnect_all(&self)
fn disconnect_all(&self)
Source§fn disconnect(&self, dispatch_uid: &str) -> bool
fn disconnect(&self, dispatch_uid: &str) -> bool
Auto Trait Implementations§
impl<T> Freeze for Signal<T>
impl<T> !RefUnwindSafe for Signal<T>
impl<T> Send for Signal<T>
impl<T> Sync for Signal<T>
impl<T> Unpin for Signal<T>
impl<T> UnsafeUnpin for Signal<T>
impl<T> !UnwindSafe for Signal<T>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = Infallible
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<E> ServerFnErrorAssertions<E> for Ewhere
E: Debug,
impl<E> ServerFnErrorAssertions<E> for Ewhere
E: Debug,
Source§fn should_contain_message(&self, expected: &str)where
E: Display,
fn should_contain_message(&self, expected: &str)where
E: Display,
Source§fn should_have_message(&self, expected: &str)where
E: Display,
fn should_have_message(&self, expected: &str)where
E: Display,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.