[−][src]Struct nuts::ActivityId
Handle to an Activity
that has been registered, with a type parameter to track the activity's type.
Can be used to add type-checked closures to the activity, which will be used as event listeners.
Implements Copy
and Clone
Implementations
impl<A: Activity> ActivityId<A>
[src]
pub fn on_enter<F>(&self, f: F) where
F: Fn(&mut A) + 'static,
[src]
F: Fn(&mut A) + 'static,
Registers a callback closure that is called when an activity changes from inactive to active.
pub fn on_enter_domained<F>(&self, f: F) where
F: Fn(&mut A, &mut DomainState) + 'static,
[src]
F: Fn(&mut A, &mut DomainState) + 'static,
Same as on_enter
but with domain access in closure
pub fn on_leave<F>(&self, f: F) where
F: Fn(&mut A) + 'static,
[src]
F: Fn(&mut A) + 'static,
Registers a callback closure that is called when an activity changes from active to inactive.
pub fn on_leave_domained<F>(&self, f: F) where
F: Fn(&mut A, &mut DomainState) + 'static,
[src]
F: Fn(&mut A, &mut DomainState) + 'static,
Same as on_leave
but with domain access in closure
pub fn subscribe<F, MSG>(&self, f: F) where
F: Fn(&mut A, &MSG) + 'static,
MSG: Any,
[src]
F: Fn(&mut A, &MSG) + 'static,
MSG: Any,
Registers a callback closure on an activity with a specific topic to listen to.
By default, the activity will only receive calls when it is active.
Use subscribe_masked
for more control over this behavior.
Example
struct MyActivity { id: usize }; struct MyMessage { text: String }; pub fn main() { let activity = nuts::new_activity(MyActivity { id: 0 } ); activity.subscribe( |activity: &mut MyActivity, message: &MyMessage| println!("Subscriber with ID {} received text: {}", activity.id, message.text) ); }
In the example above, a subscription is created that waits for messages of type MyMessage
to be published.
So far, the code inside the closure is not executed and nothing is printed to the console.
Note that the first argument of the closure is a mutable reference to the activity object. The second argument is a read-only reference to the published message. Both types must match exactly or otherwise the closure will either not be accepted by the compiler.
A function with the correct argument types can also be used to subscribe.
struct MyActivity { id: usize }; struct MyMessage { text: String }; pub fn main() { let activity = nuts::new_activity(MyActivity { id: 0 } ); activity.subscribe(MyActivity::print_text); } impl MyActivity { fn print_text(&mut self, message: &MyMessage) { println!("Subscriber with ID {} received text: {}", self.id, message.text) } }
pub fn subscribe_mut<F, MSG>(&self, f: F) where
F: Fn(&mut A, &mut MSG) + 'static,
MSG: Any,
[src]
F: Fn(&mut A, &mut MSG) + 'static,
MSG: Any,
Same as subscribe but gives mutable access to the message object.
pub fn subscribe_owned<F, MSG>(&self, f: F) where
F: Fn(&mut A, MSG) + 'static,
MSG: Any,
[src]
F: Fn(&mut A, MSG) + 'static,
MSG: Any,
Registers a callback closure on an activity with a specific topic to listen to. This variant takes ownership of the message. Only subscription per type is allowed. Othwerise, a pnic will occur when publishing.
pub fn subscribe_domained<F, MSG>(&self, f: F) where
F: Fn(&mut A, &mut DomainState, &MSG) + 'static,
MSG: Any,
[src]
F: Fn(&mut A, &mut DomainState, &MSG) + 'static,
MSG: Any,
Registers a callback closure on an activity with a specific topic to listen to.
Has mutable access to the DomainState
object.
By default, the activity will only receive calls when it is active.
Use subscribe_domained_masked
for more control over this behavior.
Panics
Panics if the activity has not been registered with a domain.
pub fn subscribe_domained_mut<F, MSG>(&self, f: F) where
F: Fn(&mut A, &mut DomainState, &mut MSG) + 'static,
MSG: Any,
[src]
F: Fn(&mut A, &mut DomainState, &mut MSG) + 'static,
MSG: Any,
Same as subscribe_domained
but gives mutable access to the message object.
pub fn subscribe_domained_owned<F, MSG>(&self, f: F) where
F: Fn(&mut A, &mut DomainState, MSG) + 'static,
MSG: Any,
[src]
F: Fn(&mut A, &mut DomainState, MSG) + 'static,
MSG: Any,
Registers a callback closure on an activity with a specific topic to listen to and access to the domain. This variant takes ownership of the message. Only subscription per type is allowed. Otherwise, a panic will occur when publishing.
pub fn subscribe_masked<F, MSG>(&self, mask: SubscriptionFilter, f: F) where
F: Fn(&mut A, &MSG) + 'static,
MSG: Any,
[src]
F: Fn(&mut A, &MSG) + 'static,
MSG: Any,
Registers a callback closure on an activity with a specific topic to listen to with filtering options.
pub fn subscribe_masked_mut<F, MSG>(&self, mask: SubscriptionFilter, f: F) where
F: Fn(&mut A, &mut MSG) + 'static,
MSG: Any,
[src]
F: Fn(&mut A, &mut MSG) + 'static,
MSG: Any,
Same as subscribe_masked
but gives mutable access to the message object.
pub fn subscribe_domained_masked<F, MSG>(&self, mask: SubscriptionFilter, f: F) where
F: Fn(&mut A, &mut DomainState, &MSG) + 'static,
MSG: Any,
[src]
F: Fn(&mut A, &mut DomainState, &MSG) + 'static,
MSG: Any,
Registers a callback closure on an activity with a specific topic to listen to with filtering options.
Has mutable access to the DomainState
object.
Panics
Panics if the activity has not been registered with a domain.
pub fn subscribe_domained_masked_mut<F, MSG>(
&self,
mask: SubscriptionFilter,
f: F
) where
F: Fn(&mut A, &mut DomainState, &mut MSG) + 'static,
MSG: Any,
[src]
&self,
mask: SubscriptionFilter,
f: F
) where
F: Fn(&mut A, &mut DomainState, &mut MSG) + 'static,
MSG: Any,
Same as subscribe_domained_masked
but gives mutable access to the message object.
pub fn set_status(&self, status: LifecycleStatus)
[src]
Changes the lifecycle status of the activity
Trait Implementations
impl<A> Clone for ActivityId<A>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<A> Copy for ActivityId<A>
[src]
impl<A: Debug> Debug for ActivityId<A>
[src]
impl<A: Eq> Eq for ActivityId<A>
[src]
impl<A: Hash> Hash for ActivityId<A>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<A> Into<UncheckedActivityId> for ActivityId<A>
[src]
fn into(self) -> UncheckedActivityId
[src]
impl<A: Ord> Ord for ActivityId<A>
[src]
fn cmp(&self, other: &ActivityId<A>) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<A: PartialEq> PartialEq<ActivityId<A>> for ActivityId<A>
[src]
fn eq(&self, other: &ActivityId<A>) -> bool
[src]
fn ne(&self, other: &ActivityId<A>) -> bool
[src]
impl<A: PartialOrd> PartialOrd<ActivityId<A>> for ActivityId<A>
[src]
fn partial_cmp(&self, other: &ActivityId<A>) -> Option<Ordering>
[src]
fn lt(&self, other: &ActivityId<A>) -> bool
[src]
fn le(&self, other: &ActivityId<A>) -> bool
[src]
fn gt(&self, other: &ActivityId<A>) -> bool
[src]
fn ge(&self, other: &ActivityId<A>) -> bool
[src]
impl<A> StructuralEq for ActivityId<A>
[src]
impl<A> StructuralPartialEq for ActivityId<A>
[src]
Auto Trait Implementations
impl<A> RefUnwindSafe for ActivityId<A> where
A: RefUnwindSafe,
A: RefUnwindSafe,
impl<A> Send for ActivityId<A> where
A: Send,
A: Send,
impl<A> Sync for ActivityId<A> where
A: Sync,
A: Sync,
impl<A> Unpin for ActivityId<A> where
A: Unpin,
A: Unpin,
impl<A> UnwindSafe for ActivityId<A> where
A: UnwindSafe,
A: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,