Improve wrap_dialogue!

This commit is contained in:
Temirkhan Myrzamadi 2020-05-24 17:15:46 +06:00
parent 6ff1800f12
commit 01dc7a0d42
2 changed files with 11 additions and 8 deletions

View file

@ -98,13 +98,10 @@ type Dialogue = Coprod!(
ReceiveFavouriteMusicState
);
wrap_dialogue!(Wrapper, Dialogue);
impl Default for Wrapper {
fn default() -> Self {
Self(Dialogue::inject(StartState))
}
}
wrap_dialogue!(
Wrapper(Dialogue),
default { Self(Dialogue::inject(StartState)) }
);
// ============================================================================
// [Control a dialogue]

View file

@ -79,7 +79,7 @@ macro_rules! dispatch {
#[macro_export]
macro_rules! wrap_dialogue {
($name:ident, $dialogue:ident) => {
($name:ident($dialogue:ident), default {$default_block:expr}) => {
struct $name($dialogue);
impl teloxide::dispatching::dialogue::DialogueWrapper<$dialogue>
@ -89,6 +89,12 @@ macro_rules! wrap_dialogue {
$name(d)
}
}
impl Default for $name {
fn default() -> $name {
$default_block
}
}
};
}