From 6331fe50cb3091af71e2267b7e7eec7182c07358 Mon Sep 17 00:00:00 2001 From: Hirrolot Date: Fri, 1 Jul 2022 02:02:45 +0600 Subject: [PATCH] Use `#[default]` for `State::Start` in dialogues Former-commit-id: 14e9fd21971180c75bf1068904092acfe839c1e9 --- examples/db_remember.rs | 9 ++------- examples/dialogue.rs | 18 +++++++++--------- examples/purchase.rs | 13 +++++-------- src/dispatching/dialogue.rs | 3 ++- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/examples/db_remember.rs b/examples/db_remember.rs index dfac7bb0..206768d9 100644 --- a/examples/db_remember.rs +++ b/examples/db_remember.rs @@ -14,18 +14,13 @@ type MyDialogue = Dialogue>; type MyStorage = std::sync::Arc>; type HandlerResult = Result<(), Box>; -#[derive(Clone, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Default, serde::Serialize, serde::Deserialize)] pub enum State { + #[default] Start, GotNumber(i32), } -impl Default for State { - fn default() -> Self { - Self::Start - } -} - #[derive(Clone, BotCommands)] #[command(rename = "lowercase", description = "These commands are supported:")] pub enum Command { diff --git a/examples/dialogue.rs b/examples/dialogue.rs index 3156b924..30636924 100644 --- a/examples/dialogue.rs +++ b/examples/dialogue.rs @@ -18,18 +18,18 @@ use teloxide::{dispatching::dialogue::InMemStorage, prelude::*}; type MyDialogue = Dialogue>; type HandlerResult = Result<(), Box>; -#[derive(Clone)] +#[derive(Clone, Default)] pub enum State { + #[default] Start, ReceiveFullName, - ReceiveAge { full_name: String }, - ReceiveLocation { full_name: String, age: u8 }, -} - -impl Default for State { - fn default() -> Self { - Self::Start - } + ReceiveAge { + full_name: String, + }, + ReceiveLocation { + full_name: String, + age: u8, + }, } #[tokio::main] diff --git a/examples/purchase.rs b/examples/purchase.rs index e8333380..74a0cd6d 100644 --- a/examples/purchase.rs +++ b/examples/purchase.rs @@ -25,17 +25,14 @@ use teloxide::{ type MyDialogue = Dialogue>; type HandlerResult = Result<(), Box>; -#[derive(Clone)] +#[derive(Clone, Default)] pub enum State { + #[default] Start, ReceiveFullName, - ReceiveProductChoice { full_name: String }, -} - -impl Default for State { - fn default() -> Self { - Self::Start - } + ReceiveProductChoice { + full_name: String, + }, } #[derive(BotCommands, Clone)] diff --git a/src/dispatching/dialogue.rs b/src/dispatching/dialogue.rs index a6661f1e..83b0239d 100644 --- a/src/dispatching/dialogue.rs +++ b/src/dispatching/dialogue.rs @@ -13,8 +13,9 @@ //! dialogues. Your dialogue state can be represented as an enumeration: //! //! ```ignore -//! #[derive(Clone)] +//! #[derive(Clone, Default)] //! pub enum State { +//! #[default] //! Start, //! ReceiveFullName, //! ReceiveAge { full_name: String },