1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::{
    core::{Handler, HandlerInput, Predicate, TryFromInput},
    dialogue::{decorator::DialogueDecorator, predicate::DialoguePredicate},
};

/// Provides a shortcut for wrapping a [`Handler`] by a [`DialogueDecorator`].
pub trait DialogueExt<P, PI, HI, HS>: Sized {
    /// Shortcut to wrap a [`Handler`] with a [`DialogueDecorator`].
    ///
    /// Example: `handler.dialogue(predicate)`.
    ///
    /// # Arguments
    ///
    /// * `predicate` - A predicate to be execute before starting the dialogue.
    ///
    /// If you don't need to start the dialogue conditionally,
    /// you can use [`DialogueDecorator::new`] directly.
    #[allow(clippy::type_complexity)]
    fn with_dialogue<B>(
        self,
        predicate: P,
    ) -> Predicate<DialoguePredicate<B, P, PI, HS>, HandlerInput, DialogueDecorator<B, Self, HI, HS>, HandlerInput>
    {
        Predicate::new(DialoguePredicate::new(predicate), DialogueDecorator::new(self))
    }
}

impl<P, PI, H, HI, HS> DialogueExt<P, PI, HI, HS> for H
where
    P: Handler<PI>,
    PI: TryFromInput,
    H: Handler<HI>,
    HI: TryFromInput,
{
}