From e094d6a20a4d09437655d948cd5f2012ffca46cf Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 31 Oct 2022 13:36:26 +0400 Subject: [PATCH 1/2] Remove `,rust` from languages in `MIGRATION_GUIDE.md` Anyway no one is rendering the syntax for diffs, while some even stop understanding that it's a diff. Former-commit-id: 2f18b5f0603a99b7a3e4472171b3e1df506719bf --- MIGRATION_GUIDE.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index 937320a7..de6665c4 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -7,12 +7,12 @@ Note that the list of required changes is not fully exhaustive and it may lack s We have introduced the new trait `CommandRepl` that replaces the old `commands_repl_(with_listener)` functions: -```diff,rust +```diff - teloxide::commands_repl(bot, answer, Command::ty()) + Command::repl(bot, answer) ``` -```diff,rust +```diff - teloxide::commands_repl_with_listener(bot, answer, listener, Command::ty()) + Command::repl_with_listener(bot, answer, listener) ``` @@ -24,12 +24,12 @@ We have introduced the new trait `CommandRepl` that replaces the old `commands_r Requests can now be `.await`ed directly, without need of `.send()` or `AutoSend`. If you previously used `AutoSend` adaptor, you can safely remove it: -```diff,rust +```diff -let bot = Bot::from_env().auto_send(); +let bot = Bot::from_env(); ``` -```diff,rust +```diff -async fn start(bot: AutoSend, dialogue: MyDialogue, msg: Message) -> HandlerResult { +async fn start(bot: Bot, dialogue: MyDialogue, msg: Message) -> HandlerResult { ``` @@ -57,7 +57,7 @@ You may need to change code accordingly: -let id: i32 = message.id; +let id: MessageId = message.id; ``` -```diff,rust +```diff let (cid, mid): (ChatId, i32) = get_message_to_delete_from_db(); -bot.delete_message(cid, mid).await?; +bot.delete_message(cid, MessageId(mid)).await?; @@ -66,7 +66,7 @@ let (cid, mid): (ChatId, i32) = get_message_to_delete_from_db(); Note that at the same time `MessageId` is now a tuple struct. If you've accessed its only field you'll need to change it too: -```diff,rust +```diff -let MessageId { message_id } = bot.copy_message(dst_chat, src_chat, mid).await?; +let MessageId(message_id) = bot.copy_message(dst_chat, src_chat, mid).await?; save_to_db(message_id); @@ -80,7 +80,7 @@ See `Sticker` documentation for more information about the new structure. You can now write `Ok(())` instead of `respond(())` at the end of closures provided to RELPs: -```diff,rust +```diff teloxide::repl(bot, |bot: Bot, msg: Message| async move { bot.send_dice(msg.chat.id).await?; - respond(()) @@ -95,7 +95,7 @@ This is because REPLs now require the closure to return `RequestError` instead o `parse_with` now accepts a Rust _path_ to a custom parser function instead of a string: -```diff,rust +```diff fn custom_parser(input: String) -> Result<(u8,), ParseError> { todo!() } @@ -110,7 +110,7 @@ enum Command { `rename` now only renames a command literally; use `rename_rule` to change the case of a command: -```diff,rust +```diff #[derive(BotCommands)] - #[command(rename = "lowercase", description = "These commands are supported:")] + #[command(rename_rule = "lowercase", description = "These commands are supported:")] From 3ecb3fb06a51578617d55a0983ab90ca84af384b Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Mon, 31 Oct 2022 13:44:32 +0400 Subject: [PATCH 2/2] Add stop token changes to the migration guide Former-commit-id: 7287ffe2f0e212a20843c709cdfbdb31fb462544 --- MIGRATION_GUIDE.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/MIGRATION_GUIDE.md b/MIGRATION_GUIDE.md index de6665c4..0c8a33bf 100644 --- a/MIGRATION_GUIDE.md +++ b/MIGRATION_GUIDE.md @@ -91,6 +91,16 @@ teloxide::repl(bot, |bot: Bot, msg: Message| async move { This is because REPLs now require the closure to return `RequestError` instead of a generic error type, so type inference works perfectly for a return value. If you use something other than `RequestError`, you can transfer your code to `teloxide::dispatching`, which still permits a generic error type. +"Stop tokens" were refactored, the trait is now removed and the types were renamed: + +```diff +-use teloxide::dispatching::stop_token::{AsyncStopToken, AsyncStopFlag}; ++use teloxide::stop::{StopToken, StopFlag, mk_stop_token}; + +-let (token, flag): (AsyncStopToken, AsyncStopFlag) = AsyncStopToken::new_pair(); ++let (token, flag): (StopToken, StopFlag) = mk_stop_token(); +``` + ### macros `parse_with` now accepts a Rust _path_ to a custom parser function instead of a string: