Skip to main content

run_event

Function run_event 

Source
pub fn run_event<P: EffectProvider + ?Sized>(
    ctx: &mut BattleCtx<'_, P>,
    hs: Vec<CollectedHandler<P>>,
    relay: RelayVar,
    fast_exit: bool,
) -> RelayVar
Expand description

The dispatch fold (design §3.4) — the workhorse.

Collects handlers (already done by the caller via collect_from_effect into hs), sorts by compare, permutes ties via the rng, then folds each handler over the relay. The loop owns hs (collected before the fold), so no handler can invalidate another mid-fold. Handlers take &mut BattleCtx — never borrowed battler refs — so the &mut borrow lives only inside each call. No RefCell, no unsafe here (the only unsafe is the provably-disjoint cross-side pair_mut).

fast_exit returns on the first Set (redirection / first-blood, the priority_event shape).