Merge pull request #607 from teloxide/fix-dialogue-state

Fix `#[derive(DialogueState)]`
This commit is contained in:
Hirrolot 2022-04-26 02:22:26 +06:00 committed by GitHub
commit cdffe0d56a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 59 additions and 53 deletions

View file

@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## unreleased ## unreleased
### Fixed
- Fix the broken `#[derive(DialogueState)]` (function return type `dptree::Handler`).
## 0.8.1 - 2022-04-24 ## 0.8.1 - 2022-04-24
### Added ### Added

View file

@ -57,7 +57,7 @@ full = [
[dependencies] [dependencies]
teloxide-core = { version = "0.5.1", default-features = false } teloxide-core = { version = "0.5.1", default-features = false }
teloxide-macros = { version = "0.6.0", optional = true } teloxide-macros = { version = "0.6.1", optional = true }
serde_json = "1.0" serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }

View file

@ -1,62 +1,64 @@
// #[cfg(feature = "macros")] #![allow(deprecated)]
// use teloxide::macros::DialogueState;
// // We put tests here because macro expand in unit tests in the crate was a
// // failure
// #[test] #[cfg(feature = "macros")]
// #[cfg(feature = "macros")] use teloxide::macros::DialogueState;
// fn compile_test() { // We put tests here because macro expand in unit tests in the crate was a
// #[allow(dead_code)] // failure
// #[derive(DialogueState, Clone)]
// #[handler_out(Result<(), teloxide::RequestError>)]
// enum State {
// #[handler(handle_start)]
// Start,
// #[handler(handle_have_data)] #[test]
// HaveData(String), #[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 { #[handler(handle_have_data)]
// fn default() -> Self { HaveData(String),
// Self::Start }
// }
// }
// async fn handle_start() -> Result<(), teloxide::RequestError> { impl Default for State {
// Ok(()) fn default() -> Self {
// } Self::Start
}
}
// async fn handle_have_data() -> Result<(), teloxide::RequestError> { async fn handle_start() -> Result<(), teloxide::RequestError> {
// Ok(()) Ok(())
// } }
// }
// #[test] async fn handle_have_data() -> Result<(), teloxide::RequestError> {
// #[cfg(feature = "macros")] Ok(())
// fn compile_test_generics() { }
// #[allow(dead_code)] }
// #[derive(DialogueState, Clone)]
// #[handler_out(Result<(), teloxide::RequestError>)]
// enum State<X: Clone + Send + Sync + 'static> {
// #[handler(handle_start)]
// Start,
// #[handler(handle_have_data)] #[test]
// HaveData(X), #[cfg(feature = "macros")]
// } fn compile_test_generics() {
#[allow(dead_code)]
#[derive(DialogueState, Clone)]
#[handler_out(Result<(), teloxide::RequestError>)]
enum State<X: Clone + Send + Sync + 'static> {
#[handler(handle_start)]
Start,
// impl<X: Clone + Send + Sync + 'static> Default for State<X> { #[handler(handle_have_data)]
// fn default() -> Self { HaveData(X),
// Self::Start }
// }
// }
// async fn handle_start() -> Result<(), teloxide::RequestError> { impl<X: Clone + Send + Sync + 'static> Default for State<X> {
// Ok(()) fn default() -> Self {
// } Self::Start
}
}
// async fn handle_have_data() -> Result<(), teloxide::RequestError> { async fn handle_start() -> Result<(), teloxide::RequestError> {
// Ok(()) Ok(())
// } }
// }
async fn handle_have_data() -> Result<(), teloxide::RequestError> {
Ok(())
}
}