pub struct EntityCountTrigger<E: Entity> { /* private fields */ }Expand description
Trigger criterion for the count of entities of a given type.
EntityCountTrigger observes
EntityCreatedEvent for a single entity type and
emits when the total number of entities of that type increases to the configured threshold.
§Construction
ⓘ
EntityCountTrigger::<E>::increases_to(threshold)§Observation
The observation data passed to
TriggerCriterion::emit_with is
EntityCountTriggerEvent:
ⓘ
pub struct EntityCountTriggerEvent<E: Entity> {
pub entity_id: EntityId<E>,
pub count: usize,
}§Semantics
As entities can only be created, not destroyed, the count of entities is monotonic. Thus, this
criterion does not use Direction or TriggerMode.
- It fires when a creation makes the count equal to the threshold.
- The observed count always equals the threshold the trigger was created with.
- If the entity population already equals or exceeds the threshold before the trigger is registered, it will never emit.
- A threshold of
0will not be reached by an entity creation and is therefore not allowed.
§Example
use ixa::{Context, ContextEntitiesExt, define_entity, IxaEvent};
use ixa::entity::EntityId;
use ixa::triggers::{ContextTriggersExt, EntityCountTrigger, TriggerCriterion};
define_entity!(Case);
// The event records which case caused us to reach the threshold and
// the value of the threshold itself (as `count`).
#[derive(IxaEvent)]
struct SecondCase {
case_id: EntityId<Case>,
count: usize,
}
let mut context = Context::new();
context.register_trigger(
EntityCountTrigger::increases_to(2)
.emit_with(|observation| SecondCase {
case_id: observation.entity_id,
count: observation.count,
}),
);
context.subscribe_to_event(|_context, _event: SecondCase| {
// respond when the second Case entity is created
});Implementations§
Source§impl<E: Entity> EntityCountTrigger<E>
impl<E: Entity> EntityCountTrigger<E>
pub fn increases_to(threshold: usize) -> Self
Trait Implementations§
Source§impl<E: Entity> TriggerCriterion for EntityCountTrigger<E>
impl<E: Entity> TriggerCriterion for EntityCountTrigger<E>
Source§type Observation = EntityCountTriggerEvent<E>
type Observation = EntityCountTriggerEvent<E>
The data that represents what is observed when the criterion is met.
This data is passed to the handler installed for this criterion.
Source§fn install<F>(self, context: &mut Context, on_match: F)
fn install<F>(self, context: &mut Context, on_match: F)
Install the criterion’s monitoring logic in
context.Source§fn emit_with<Ev, F>(self, make_event: F) -> Trigger<Self, Ev, F>
fn emit_with<Ev, F>(self, make_event: F) -> Trigger<Self, Ev, F>
Bind this criterion to a constructor for a concrete user event.
Source§fn emit_default<Ev>(self) -> Trigger<Self, Ev, impl Fn(Self::Observation) -> Ev>
fn emit_default<Ev>(self) -> Trigger<Self, Ev, impl Fn(Self::Observation) -> Ev>
Bind this criterion to a default-valued concrete user event.
Source§fn emit_value<Ev>(
self,
event: Ev,
) -> Trigger<Self, Ev, impl Fn(Self::Observation) -> Ev>where
Ev: IxaEvent,
fn emit_value<Ev>(
self,
event: Ev,
) -> Trigger<Self, Ev, impl Fn(Self::Observation) -> Ev>where
Ev: IxaEvent,
Bind this criterion to a constant concrete user event value.
Auto Trait Implementations§
impl<E> Freeze for EntityCountTrigger<E>
impl<E> RefUnwindSafe for EntityCountTrigger<E>
impl<E> Send for EntityCountTrigger<E>
impl<E> Sync for EntityCountTrigger<E>
impl<E> Unpin for EntityCountTrigger<E>
impl<E> UnsafeUnpin for EntityCountTrigger<E>
impl<E> UnwindSafe for EntityCountTrigger<E>
Blanket Implementations§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
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<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Returns the layout of the type.