Fix the docs

This commit is contained in:
Temirkhan Myrzamadi 2020-07-26 23:37:56 +06:00
parent 8b7a6e019f
commit f9c192aad0
9 changed files with 24 additions and 11 deletions

View file

@ -203,6 +203,12 @@ pub enum Dialogue {
ReceiveAge(ReceiveAgeState),
ReceiveLocation(ReceiveLocationState),
}
impl Default for Dialogue {
fn default() -> Self {
Self::Start(StartState)
}
}
```
([dialogue_bot/src/dialogue/states/start.rs](https://github.com/teloxide/teloxide/blob/master/examples/dialogue_bot/src/dialogue/states/start.rs))

View file

@ -15,7 +15,6 @@ frunk-core = { git = "https://github.com/Hirrolot/frunk", branch = "append-to-hl
pretty_env_logger = "0.4.0"
futures = "0.3.5"
smart-default = "0.6.0"
derive_more = "0.99.9"
teloxide = { path = "../../", features = ["frunk"] }
teloxide-macros = { git = "http://github.com/teloxide/teloxide-macros", branch = "master" }

View file

@ -3,13 +3,19 @@ mod states;
use crate::dialogue::states::{
ReceiveAgeState, ReceiveFullNameState, ReceiveLocationState, StartState,
};
use derive_more::From;
use teloxide_macros::Transition;
#[derive(Transition, SmartDefault, From)]
#[derive(Transition, From)]
pub enum Dialogue {
#[default]
Start(StartState),
ReceiveFullName(ReceiveFullNameState),
ReceiveAge(ReceiveAgeState),
ReceiveLocation(ReceiveLocationState),
}
impl Default for Dialogue {
fn default() -> Self {
Self::Start(StartState)
}
}

View file

@ -2,6 +2,7 @@ use crate::dialogue::{
states::receive_location::ReceiveLocationState, Dialogue,
};
use teloxide::prelude::*;
use teloxide_macros::teloxide;
#[derive(Generic)]
pub struct ReceiveAgeState {

View file

@ -1,5 +1,6 @@
use crate::dialogue::{states::receive_age::ReceiveAgeState, Dialogue};
use teloxide::prelude::*;
use teloxide_macros::teloxide;
#[derive(Generic)]
pub struct ReceiveFullNameState;

View file

@ -1,5 +1,6 @@
use crate::dialogue::Dialogue;
use teloxide::prelude::*;
use teloxide_macros::teloxide;
#[derive(Generic)]
pub struct ReceiveLocationState {

View file

@ -1,5 +1,6 @@
use crate::dialogue::{states::ReceiveFullNameState, Dialogue};
use teloxide::prelude::*;
use teloxide_macros::teloxide;
#[derive(Default)]
pub struct StartState;

View file

@ -17,15 +17,8 @@
#![allow(clippy::trivial_regex)]
#![allow(dead_code)]
#[macro_use]
extern crate smart_default;
#[macro_use]
extern crate derive_more;
#[macro_use]
extern crate frunk;
extern crate frunk_core;
#[macro_use]
extern crate teloxide_macros;
mod dialogue;

View file

@ -88,7 +88,8 @@
//! // No panic because of std::convert::Infallible.
//! let dialogue = dialogue.unwrap();
//! dialogue
//! .react(cx)
//! // Instead of () you can pass an arbitrary value, see below.
//! .react(cx, ())
//! .await
//! .expect("Something wrong with the bot!")
//! },
@ -103,6 +104,10 @@
//! - `#[derive(Transition)]` implements [`Transition`] for `D`, if all the
//! variants implement [`SubTransition`].
//!
//! `()` in `.react(cx, ())` is an arbitrary value, which you can pass into
//! subtransitions. Just append `ans: T` to the parameters of the
//! subtransitions to pass a differen type.
//!
//! See [examples/dialogue_bot] as a real example.
//!
//! [`Transition`]: crate::dispatching::dialogue::Transition