[][src]Struct weasel::event::Conditional

pub struct Conditional<'a, R, T, P> where
    R: BattleRules,
    T: EventTrigger<'a, R, P>,
    P: 'a + EventProcessor<R>, 
{ /* fields omitted */ }

Decorator for event triggers to add a condition on the generated event prototype.

Examples

use weasel::{
    battle_rules, event::Conditional, event::DummyEvent, rules::empty::*, Battle, BattleRules,
    BattleState, EventTrigger, Server, WeaselError,
};

battle_rules! {}

let battle = Battle::builder(CustomRules::new()).build();
let mut server = Server::builder(battle).build();

let result = Conditional::new(
    DummyEvent::trigger(&mut server),
    std::rc::Rc::new(|state: &BattleState<CustomRules>| {
        state
            .entities()
            .teams()
            .count() == 42
    }),
)
.fire();
assert_eq!(
    result.err().map(|e| e.unfold()),
    Some(WeaselError::ConditionUnsatisfied)
);

Implementations

impl<'a, R, T, P> Conditional<'a, R, T, P> where
    R: BattleRules,
    T: EventTrigger<'a, R, P>,
    P: 'a + EventProcessor<R>,
    Condition<R>: Clone
[src]

pub fn new(trigger: T, condition: Condition<R>) -> Self[src]

Creates a new Conditional decorator for an EventTrigger.

Trait Implementations

impl<'a, R, T, P> EventTrigger<'a, R, P> for Conditional<'a, R, T, P> where
    R: BattleRules,
    T: EventTrigger<'a, R, P>,
    P: 'a + EventProcessor<R>,
    Condition<R>: Clone
[src]

Auto Trait Implementations

impl<'a, R, T, P> !RefUnwindSafe for Conditional<'a, R, T, P>

impl<'a, R, T, P> !Send for Conditional<'a, R, T, P>

impl<'a, R, T, P> !Sync for Conditional<'a, R, T, P>

impl<'a, R, T, P> Unpin for Conditional<'a, R, T, P> where
    T: Unpin

impl<'a, R, T, P> !UnwindSafe for Conditional<'a, R, T, P>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,