From e7fb02e8feeb0dfeefdc59f4b014680863ea87ef Mon Sep 17 00:00:00 2001 From: Hirrolot Date: Sun, 24 Jul 2022 19:14:22 +0600 Subject: [PATCH] Make `dialogue` doc examples verifiable Former-commit-id: 793dbcfcdb1276f03a84fb617c6bce651fbf609f --- src/dispatching/dialogue.rs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/dispatching/dialogue.rs b/src/dispatching/dialogue.rs index 3af1ecc0..724af2e2 100644 --- a/src/dispatching/dialogue.rs +++ b/src/dispatching/dialogue.rs @@ -13,21 +13,30 @@ //! [`examples/dialogue.rs`] clearly demonstrates the typical usage of //! dialogues. Your dialogue state can be represented as an enumeration: //! -//! ```ignore +//! ```no_run //! #[derive(Clone, Default)] //! pub enum State { //! #[default] //! Start, //! ReceiveFullName, -//! ReceiveAge { full_name: String }, -//! ReceiveLocation { full_name: String, age: u8 }, +//! ReceiveAge { +//! full_name: String, +//! }, +//! ReceiveLocation { +//! full_name: String, +//! age: u8, +//! }, //! } //! ``` //! //! Each state is associated with its respective handler: e.g., when a dialogue //! state is `ReceiveAge`, `receive_age` is invoked: //! -//! ```ignore +//! ```no_run +//! # use teloxide::{dispatching::dialogue::InMemStorage, prelude::*}; +//! # type MyDialogue = Dialogue>; +//! # type HandlerResult = Result<(), Box>; +//! # #[derive(Clone, Debug)] enum State { ReceiveLocation { full_name: String, age: u8 } } //! async fn receive_age( //! bot: AutoSend, //! msg: Message, @@ -55,13 +64,17 @@ //! the dialogue, just call [`Dialogue::exit`] and it will be removed from the //! underlying storage: //! -//! ```ignore +//! ```no_run +//! # use teloxide::{dispatching::dialogue::InMemStorage, prelude::*}; +//! # type MyDialogue = Dialogue>; +//! # type HandlerResult = Result<(), Box>; +//! # #[derive(Clone, Debug)] enum State {} //! async fn receive_location( //! bot: AutoSend, //! msg: Message, //! dialogue: MyDialogue, //! (full_name, age): (String, u8), // Available from `State::ReceiveLocation`. -//! ) -> anyhow::Result<()> { +//! ) -> HandlerResult { //! match msg.text() { //! Some(location) => { //! let message =