From 19595c1e03088b4f2948ea9867aa9a837e982224 Mon Sep 17 00:00:00 2001 From: Hirrolot Date: Tue, 26 Apr 2022 01:55:29 +0600 Subject: [PATCH] Fix `#[derive(DialogueState)]` --- CHANGELOG.md | 4 ++ Cargo.toml | 2 +- tests/dialogue_state.rs | 106 ++++++++++++++++++++-------------------- 3 files changed, 59 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2886288..4d8e53bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## unreleased +### Fixed + + - Fix the broken `#[derive(DialogueState)]` (function return type `dptree::Handler`). + ## 0.8.1 - 2022-04-24 ### Added diff --git a/Cargo.toml b/Cargo.toml index e48440a8..8b3dc8ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -57,7 +57,7 @@ full = [ [dependencies] teloxide-core = { version = "0.5.1", default-features = false } -teloxide-macros = { version = "0.6.0", optional = true } +teloxide-macros = { git = "https://github.com/teloxide/teloxide-macros.git", rev = "a3e69b811e753d9f747aaefa7de40bf0c211bfb8", optional = true } serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } diff --git a/tests/dialogue_state.rs b/tests/dialogue_state.rs index 1ae10154..567d8f51 100644 --- a/tests/dialogue_state.rs +++ b/tests/dialogue_state.rs @@ -1,62 +1,64 @@ -// #[cfg(feature = "macros")] -// use teloxide::macros::DialogueState; -// // We put tests here because macro expand in unit tests in the crate was a -// // failure +#![allow(deprecated)] -// #[test] -// #[cfg(feature = "macros")] -// fn compile_test() { -// #[allow(dead_code)] -// #[derive(DialogueState, Clone)] -// #[handler_out(Result<(), teloxide::RequestError>)] -// enum State { -// #[handler(handle_start)] -// Start, +#[cfg(feature = "macros")] +use teloxide::macros::DialogueState; +// We put tests here because macro expand in unit tests in the crate was a +// failure -// #[handler(handle_have_data)] -// HaveData(String), -// } +#[test] +#[cfg(feature = "macros")] +fn compile_test() { + #[allow(dead_code)] + #[derive(DialogueState, Clone)] + #[handler_out(Result<(), teloxide::RequestError>)] + enum State { + #[handler(handle_start)] + Start, -// impl Default for State { -// fn default() -> Self { -// Self::Start -// } -// } + #[handler(handle_have_data)] + HaveData(String), + } -// async fn handle_start() -> Result<(), teloxide::RequestError> { -// Ok(()) -// } + impl Default for State { + fn default() -> Self { + Self::Start + } + } -// async fn handle_have_data() -> Result<(), teloxide::RequestError> { -// Ok(()) -// } -// } + async fn handle_start() -> Result<(), teloxide::RequestError> { + Ok(()) + } -// #[test] -// #[cfg(feature = "macros")] -// fn compile_test_generics() { -// #[allow(dead_code)] -// #[derive(DialogueState, Clone)] -// #[handler_out(Result<(), teloxide::RequestError>)] -// enum State { -// #[handler(handle_start)] -// Start, + async fn handle_have_data() -> Result<(), teloxide::RequestError> { + Ok(()) + } +} -// #[handler(handle_have_data)] -// HaveData(X), -// } +#[test] +#[cfg(feature = "macros")] +fn compile_test_generics() { + #[allow(dead_code)] + #[derive(DialogueState, Clone)] + #[handler_out(Result<(), teloxide::RequestError>)] + enum State { + #[handler(handle_start)] + Start, -// impl Default for State { -// fn default() -> Self { -// Self::Start -// } -// } + #[handler(handle_have_data)] + HaveData(X), + } -// async fn handle_start() -> Result<(), teloxide::RequestError> { -// Ok(()) -// } + impl Default for State { + fn default() -> Self { + Self::Start + } + } -// async fn handle_have_data() -> Result<(), teloxide::RequestError> { -// Ok(()) -// } -// } + async fn handle_start() -> Result<(), teloxide::RequestError> { + Ok(()) + } + + async fn handle_have_data() -> Result<(), teloxide::RequestError> { + Ok(()) + } +}