mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 17:52:12 +01:00
Use #[default]
for State::Start
in dialogues
This commit is contained in:
parent
68f9ccfcb1
commit
14e9fd2197
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 MyStorage = std::sync::Arc<ErasedStorage<State>>;
|
||||||
type HandlerResult = Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
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 {
|
pub enum State {
|
||||||
|
#[default]
|
||||||
Start,
|
Start,
|
||||||
GotNumber(i32),
|
GotNumber(i32),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for State {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::Start
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, BotCommands)]
|
#[derive(Clone, BotCommands)]
|
||||||
#[command(rename = "lowercase", description = "These commands are supported:")]
|
#[command(rename = "lowercase", description = "These commands are supported:")]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
|
|
|
@ -18,18 +18,18 @@ use teloxide::{dispatching::dialogue::InMemStorage, prelude::*};
|
||||||
type MyDialogue = Dialogue<State, InMemStorage<State>>;
|
type MyDialogue = Dialogue<State, InMemStorage<State>>;
|
||||||
type HandlerResult = Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
type HandlerResult = Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Default)]
|
||||||
pub enum State {
|
pub enum State {
|
||||||
|
#[default]
|
||||||
Start,
|
Start,
|
||||||
ReceiveFullName,
|
ReceiveFullName,
|
||||||
ReceiveAge { full_name: String },
|
ReceiveAge {
|
||||||
ReceiveLocation { full_name: String, age: u8 },
|
full_name: String,
|
||||||
}
|
},
|
||||||
|
ReceiveLocation {
|
||||||
impl Default for State {
|
full_name: String,
|
||||||
fn default() -> Self {
|
age: u8,
|
||||||
Self::Start
|
},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
|
|
|
@ -25,17 +25,14 @@ use teloxide::{
|
||||||
type MyDialogue = Dialogue<State, InMemStorage<State>>;
|
type MyDialogue = Dialogue<State, InMemStorage<State>>;
|
||||||
type HandlerResult = Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
type HandlerResult = Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Default)]
|
||||||
pub enum State {
|
pub enum State {
|
||||||
|
#[default]
|
||||||
Start,
|
Start,
|
||||||
ReceiveFullName,
|
ReceiveFullName,
|
||||||
ReceiveProductChoice { full_name: String },
|
ReceiveProductChoice {
|
||||||
}
|
full_name: String,
|
||||||
|
},
|
||||||
impl Default for State {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::Start
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(BotCommands, Clone)]
|
#[derive(BotCommands, Clone)]
|
||||||
|
|
|
@ -13,8 +13,9 @@
|
||||||
//! dialogues. Your dialogue state can be represented as an enumeration:
|
//! dialogues. Your dialogue state can be represented as an enumeration:
|
||||||
//!
|
//!
|
||||||
//! ```ignore
|
//! ```ignore
|
||||||
//! #[derive(Clone)]
|
//! #[derive(Clone, Default)]
|
||||||
//! pub enum State {
|
//! pub enum State {
|
||||||
|
//! #[default]
|
||||||
//! Start,
|
//! Start,
|
||||||
//! ReceiveFullName,
|
//! ReceiveFullName,
|
||||||
//! ReceiveAge { full_name: String },
|
//! ReceiveAge { full_name: String },
|
||||||
|
|
Loading…
Reference in a new issue