From 3075dfd8acbecdcc4a1c9df2b349eb1b8232af12 Mon Sep 17 00:00:00 2001 From: Hirrolot Date: Thu, 24 Mar 2022 17:30:36 +0600 Subject: [PATCH] Use `std::error::Error` instead of `anyhow` in the examples --- Cargo.toml | 1 - examples/dialogue.rs | 15 ++++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index bc0a3138..3c3462d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -89,7 +89,6 @@ bincode = { version = "1.3", optional = true } rand = "0.8.3" pretty_env_logger = "0.4.0" once_cell = "1.9.0" -anyhow = "1.0.52" serde = "1" serde_json = "1" tokio = { version = "1.8", features = ["fs", "rt-multi-thread", "macros"] } diff --git a/examples/dialogue.rs b/examples/dialogue.rs index 5aa3b142..7c3438c9 100644 --- a/examples/dialogue.rs +++ b/examples/dialogue.rs @@ -16,9 +16,10 @@ use teloxide::{dispatching::dialogue::InMemStorage, macros::DialogueState, prelude::*}; type MyDialogue = Dialogue>; +type HandlerResult = Result<(), Box>; #[derive(DialogueState, Clone)] -#[handler_out(anyhow::Result<()>)] +#[handler_out(HandlerResult)] pub enum State { #[handler(handle_start)] Start, @@ -59,11 +60,7 @@ async fn main() { .await; } -async fn handle_start( - bot: AutoSend, - msg: Message, - dialogue: MyDialogue, -) -> anyhow::Result<()> { +async fn handle_start(bot: AutoSend, msg: Message, dialogue: MyDialogue) -> HandlerResult { bot.send_message(msg.chat.id, "Let's start! What's your full name?").await?; dialogue.update(State::ReceiveFullName).await?; Ok(()) @@ -73,7 +70,7 @@ async fn handle_receive_full_name( bot: AutoSend, msg: Message, dialogue: MyDialogue, -) -> anyhow::Result<()> { +) -> HandlerResult { match msg.text() { Some(text) => { bot.send_message(msg.chat.id, "How old are you?").await?; @@ -92,7 +89,7 @@ async fn handle_receive_age( msg: Message, dialogue: MyDialogue, (full_name,): (String,), // Available from `State::ReceiveAge`. -) -> anyhow::Result<()> { +) -> HandlerResult { match msg.text().map(|text| text.parse::()) { Some(Ok(age)) => { bot.send_message(msg.chat.id, "What's your location?").await?; @@ -111,7 +108,7 @@ async fn handle_receive_location( msg: Message, dialogue: MyDialogue, (full_name, age): (String, u8), // Available from `State::ReceiveLocation`. -) -> anyhow::Result<()> { +) -> HandlerResult { match msg.text() { Some(location) => { let message = format!("Full name: {}\nAge: {}\nLocation: {}", full_name, age, location);