Merge pull request #669 from teloxide/use-default-enum-variant

Use `#[default]` for `State::Start` in dialogues

Former-commit-id: 9290665d04
This commit is contained in:
Hirrolot 2022-07-04 21:59:34 +06:00 committed by GitHub
commit 6fcec547f1
4 changed files with 18 additions and 25 deletions

View file

@ -14,18 +14,13 @@ type MyDialogue = Dialogue<State, ErasedStorage<State>>;
type MyStorage = std::sync::Arc<ErasedStorage<State>>;
type HandlerResult = Result<(), Box<dyn std::error::Error + Send + Sync>>;
#[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 {

View file

@ -18,18 +18,18 @@ use teloxide::{dispatching::dialogue::InMemStorage, prelude::*};
type MyDialogue = Dialogue<State, InMemStorage<State>>;
type HandlerResult = Result<(), Box<dyn std::error::Error + Send + Sync>>;
#[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]

View file

@ -25,17 +25,14 @@ use teloxide::{
type MyDialogue = Dialogue<State, InMemStorage<State>>;
type HandlerResult = Result<(), Box<dyn std::error::Error + Send + Sync>>;
#[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)]

View file

@ -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 },