mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
Remove DialogueWithCx::unpack
This commit is contained in:
parent
19730fb923
commit
477d8a67d3
5 changed files with 26 additions and 33 deletions
13
README.md
13
README.md
|
@ -305,12 +305,13 @@ async fn main() {
|
|||
let bot = Bot::from_env();
|
||||
|
||||
Dispatcher::new(bot)
|
||||
.messages_handler(DialogueDispatcher::new(|input: In| async move {
|
||||
// No panic because of std::convert::Infallible.
|
||||
let (cx, dialogue) = input.unpack();
|
||||
|
||||
dialogue.react(cx).await.expect("Something wrong with the bot!")
|
||||
}))
|
||||
.messages_handler(DialogueDispatcher::new(
|
||||
|DialogueWithCx { cx, dialogue }: In| async move {
|
||||
// No panic because of std::convert::Infallible.
|
||||
let dialogue = dialogue.unwrap();
|
||||
dialogue.react(cx).await.expect("Something wrong with the bot!")
|
||||
},
|
||||
))
|
||||
.dispatch()
|
||||
.await;
|
||||
}
|
||||
|
|
|
@ -49,12 +49,13 @@ async fn run() {
|
|||
let bot = Bot::from_env();
|
||||
|
||||
Dispatcher::new(bot)
|
||||
.messages_handler(DialogueDispatcher::new(|input: In| async move {
|
||||
// No panic because of std::convert::Infallible.
|
||||
let (cx, dialogue) = input.unpack();
|
||||
|
||||
dialogue.react(cx).await.expect("Something wrong with the bot!")
|
||||
}))
|
||||
.messages_handler(DialogueDispatcher::new(
|
||||
|DialogueWithCx { cx, dialogue }: In| async move {
|
||||
// No panic because of std::convert::Infallible.
|
||||
let dialogue = dialogue.unwrap();
|
||||
dialogue.react(cx).await.expect("Something wrong with the bot!")
|
||||
},
|
||||
))
|
||||
.dispatch()
|
||||
.await;
|
||||
}
|
||||
|
|
|
@ -35,9 +35,9 @@ async fn run() {
|
|||
let bot = Bot::from_env();
|
||||
Dispatcher::new(bot)
|
||||
.messages_handler(DialogueDispatcher::with_storage(
|
||||
|input: In| async move {
|
||||
|DialogueWithCx { cx, dialogue }: In| async move {
|
||||
// No panic because of std::convert::Infallible.
|
||||
let (cx, dialogue) = input.unpack();
|
||||
let dialogue = dialogue.unwrap();
|
||||
|
||||
dialogue
|
||||
.react(cx)
|
||||
|
|
|
@ -13,19 +13,6 @@ pub struct DialogueWithCx<Upd, D, E> {
|
|||
pub dialogue: Result<D, E>,
|
||||
}
|
||||
|
||||
impl<Upd, D, E> DialogueWithCx<Upd, D, E> {
|
||||
/// Returns the inner `UpdateWithCx<Upd>` and an unwrapped dialogue.
|
||||
///
|
||||
/// # Panics
|
||||
/// If `self.dialogue` is `Err`.
|
||||
pub fn unpack(self) -> (UpdateWithCx<Upd>, D)
|
||||
where
|
||||
E: Debug,
|
||||
{
|
||||
(self.cx, self.dialogue.unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
impl<Upd, D, E> DialogueWithCx<Upd, D, E> {
|
||||
/// Creates a new instance with the provided fields.
|
||||
pub fn new(cx: UpdateWithCx<Upd>, dialogue: D) -> Self {
|
||||
|
|
|
@ -83,12 +83,16 @@
|
|||
//! let bot = Bot::from_env();
|
||||
//!
|
||||
//! Dispatcher::new(bot)
|
||||
//! .messages_handler(DialogueDispatcher::new(|input: In| async move {
|
||||
//! // No panic because of std::convert::Infallible.
|
||||
//! let (cx, dialogue) = input.unpack();
|
||||
//!
|
||||
//! dialogue.react(cx).await.expect("Something wrong with the bot!")
|
||||
//! }))
|
||||
//! .messages_handler(DialogueDispatcher::new(
|
||||
//! |DialogueWithCx { cx, dialogue }: In| async move {
|
||||
//! // No panic because of std::convert::Infallible.
|
||||
//! let dialogue = dialogue.unwrap();
|
||||
//! dialogue
|
||||
//! .react(cx)
|
||||
//! .await
|
||||
//! .expect("Something wrong with the bot!")
|
||||
//! },
|
||||
//! ))
|
||||
//! .dispatch()
|
||||
//! .await;
|
||||
//! }
|
||||
|
|
Loading…
Add table
Reference in a new issue