mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
Use std::error::Error
instead of anyhow
in the examples
This commit is contained in:
parent
fa5d1f738b
commit
ae227be4f0
2 changed files with 6 additions and 10 deletions
|
@ -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"] }
|
||||
|
|
|
@ -16,9 +16,10 @@
|
|||
use teloxide::{dispatching::dialogue::InMemStorage, macros::DialogueState, prelude::*};
|
||||
|
||||
type MyDialogue = Dialogue<State, InMemStorage<State>>;
|
||||
type HandlerResult = Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
||||
|
||||
#[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<Bot>,
|
||||
msg: Message,
|
||||
dialogue: MyDialogue,
|
||||
) -> anyhow::Result<()> {
|
||||
async fn handle_start(bot: AutoSend<Bot>, 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<Bot>,
|
||||
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::<u8>()) {
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue