mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
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:
commit
6fcec547f1
4 changed files with 18 additions and 25 deletions
|
@ -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 {
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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 },
|
||||
|
|
Loading…
Reference in a new issue