#[teloxide(transition)] -> #[teloxide(subtransition)]

This commit is contained in:
Temirkhan Myrzamadi 2020-07-27 00:52:03 +06:00
parent d43d74d80c
commit af2aa218e7
9 changed files with 17 additions and 17 deletions

View file

@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- `BotBuilder`, which allows setting a default `ParseMode`. - `BotBuilder`, which allows setting a default `ParseMode`.
- The `Transition`, `Subtransition`, `SubtransitionOutputType` traits. - The `Transition`, `Subtransition`, `SubtransitionOutputType` traits.
- A nicer approach to manage dialogues via `#[derive(Transition)]` + `#[teloxide(transition)]` (see `examples/dialogue_bot`). - A nicer approach to manage dialogues via `#[derive(Transition)]` + `#[teloxide(subtransition)]` (see `examples/dialogue_bot`).
### Deprecated ### Deprecated
- `Bot::{from_env_with_client, new, with_client}`. - `Bot::{from_env_with_client, new, with_client}`.

View file

@ -208,7 +208,7 @@ impl Default for Dialogue {
#[derive(Default)] #[derive(Default)]
pub struct StartState; pub struct StartState;
#[teloxide(transition)] #[teloxide(subtransition)]
async fn start(_state: StartState, cx: TransitionIn, _ans: String) -> TransitionOut<Dialogue> { async fn start(_state: StartState, cx: TransitionIn, _ans: String) -> TransitionOut<Dialogue> {
cx.answer_str("Let's start! What's your full name?").await?; cx.answer_str("Let's start! What's your full name?").await?;
next(ReceiveFullNameState) next(ReceiveFullNameState)
@ -224,7 +224,7 @@ pub struct ReceiveAgeState {
pub full_name: String, pub full_name: String,
} }
#[teloxide(transition)] #[teloxide(subtransition)]
async fn receive_age_state( async fn receive_age_state(
state: ReceiveAgeState, state: ReceiveAgeState,
cx: TransitionIn, cx: TransitionIn,
@ -250,7 +250,7 @@ async fn receive_age_state(
#[derive(Generic)] #[derive(Generic)]
pub struct ReceiveFullNameState; pub struct ReceiveFullNameState;
#[teloxide(transition)] #[teloxide(subtransition)]
async fn receive_full_name( async fn receive_full_name(
state: ReceiveFullNameState, state: ReceiveFullNameState,
cx: TransitionIn, cx: TransitionIn,
@ -271,7 +271,7 @@ pub struct ReceiveLocationState {
pub age: u8, pub age: u8,
} }
#[teloxide(transition)] #[teloxide(subtransition)]
async fn receive_location( async fn receive_location(
state: ReceiveLocationState, state: ReceiveLocationState,
cx: TransitionIn, cx: TransitionIn,

View file

@ -7,7 +7,7 @@ pub struct ReceiveAgeState {
pub full_name: String, pub full_name: String,
} }
#[teloxide(transition)] #[teloxide(subtransition)]
async fn receive_age_state( async fn receive_age_state(
state: ReceiveAgeState, state: ReceiveAgeState,
cx: TransitionIn, cx: TransitionIn,

View file

@ -5,7 +5,7 @@ use teloxide_macros::teloxide;
#[derive(Generic)] #[derive(Generic)]
pub struct ReceiveFullNameState; pub struct ReceiveFullNameState;
#[teloxide(transition)] #[teloxide(subtransition)]
async fn receive_full_name( async fn receive_full_name(
state: ReceiveFullNameState, state: ReceiveFullNameState,
cx: TransitionIn, cx: TransitionIn,

View file

@ -8,7 +8,7 @@ pub struct ReceiveLocationState {
pub age: u8, pub age: u8,
} }
#[teloxide(transition)] #[teloxide(subtransition)]
async fn receive_location( async fn receive_location(
state: ReceiveLocationState, state: ReceiveLocationState,
cx: TransitionIn, cx: TransitionIn,

View file

@ -5,7 +5,7 @@ use teloxide_macros::teloxide;
#[derive(Default)] #[derive(Default)]
pub struct StartState; pub struct StartState;
#[teloxide(transition)] #[teloxide(subtransition)]
async fn start(_state: StartState, cx: TransitionIn, _ans: String) -> TransitionOut<Dialogue> { async fn start(_state: StartState, cx: TransitionIn, _ans: String) -> TransitionOut<Dialogue> {
cx.answer_str("Let's start! What's your full name?").await?; cx.answer_str("Let's start! What's your full name?").await?;
next(ReceiveFullNameState) next(ReceiveFullNameState)

View file

@ -3,7 +3,7 @@ use teloxide_macros::teloxide;
use super::states::*; use super::states::*;
#[teloxide(transition)] #[teloxide(subtransition)]
async fn start(state: StartState, cx: TransitionIn, ans: String) -> TransitionOut<Dialogue> { async fn start(state: StartState, cx: TransitionIn, ans: String) -> TransitionOut<Dialogue> {
if let Ok(number) = ans.parse() { if let Ok(number) = ans.parse() {
cx.answer_str(format!("Remembered number {}. Now use /get or /reset", number)).await?; cx.answer_str(format!("Remembered number {}. Now use /get or /reset", number)).await?;
@ -14,7 +14,7 @@ async fn start(state: StartState, cx: TransitionIn, ans: String) -> TransitionOu
} }
} }
#[teloxide(transition)] #[teloxide(subtransition)]
async fn have_number( async fn have_number(
state: HaveNumberState, state: HaveNumberState,
cx: TransitionIn, cx: TransitionIn,

View file

@ -26,7 +26,7 @@
//! //!
//! To avoid boilerplate, teloxide exports these convenient things: the [`next`] //! To avoid boilerplate, teloxide exports these convenient things: the [`next`]
//! and [`exit`] functions, and `#[derive(BotDialogue)]` with //! and [`exit`] functions, and `#[derive(BotDialogue)]` with
//! `#[teloxide(transition)]`. Here's how your dialogues management code //! `#[teloxide(subtransition)]`. Here's how your dialogues management code
//! skeleton should look like: //! skeleton should look like:
//! //!
//! ```no_run //! ```no_run
@ -41,17 +41,17 @@
//! //!
//! type Out = TransitionOut<D>; //! type Out = TransitionOut<D>;
//! //!
//! #[teloxide(transition)] //! #[teloxide(subtransition)]
//! async fn _1_transition(_state: _1State, _cx: TransitionIn) -> Out { //! async fn _1_transition(_state: _1State, _cx: TransitionIn) -> Out {
//! todo!() //! todo!()
//! } //! }
//! //!
//! #[teloxide(transition)] //! #[teloxide(subtransition)]
//! async fn _2_transition(_state: _2State, _cx: TransitionIn) -> Out { //! async fn _2_transition(_state: _2State, _cx: TransitionIn) -> Out {
//! todo!() //! todo!()
//! } //! }
//! //!
//! #[teloxide(transition)] //! #[teloxide(subtransition)]
//! async fn _3_transition(_state: _3State, _cx: TransitionIn) -> Out { //! async fn _3_transition(_state: _3State, _cx: TransitionIn) -> Out {
//! todo!() //! todo!()
//! } //! }
@ -99,7 +99,7 @@
//! } //! }
//! ``` //! ```
//! //!
//! - `#[teloxide(transition)]` implements [`Subtransition`] for the first //! - `#[teloxide(subtransition)]` implements [`Subtransition`] for the first
//! argument of a function. //! argument of a function.
//! - `#[derive(Transition)]` implements [`Transition`] for `D`, if all the //! - `#[derive(Transition)]` implements [`Transition`] for `D`, if all the
//! variants implement [`Subtransition`]. //! variants implement [`Subtransition`].

View file

@ -38,7 +38,7 @@ where
/// A type returned from a FSM subtransition function. /// A type returned from a FSM subtransition function.
/// ///
/// Now it is used only inside `#[teloxide(transition)]` for type inference. /// Now it is used only inside `#[teloxide(subtransition)]` for type inference.
pub trait SubtransitionOutputType { pub trait SubtransitionOutputType {
type Output; type Output;
} }