mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-19 13:38:50 +01:00
65 lines
1.5 KiB
Rust
65 lines
1.5 KiB
Rust
|
#[cfg(feature = "macros")]
|
||
|
use teloxide::macros::DialogueState;
|
||
|
// We put tests here because macro expand in unit tests in the crate was a
|
||
|
// failure
|
||
|
|
||
|
#[test]
|
||
|
#[cfg(feature = "macros")]
|
||
|
fn compile_test() {
|
||
|
#[allow(dead_code)]
|
||
|
#[derive(DialogueState, Clone)]
|
||
|
#[out(Result<(), teloxide::RequestError>)]
|
||
|
#[store(teloxide::dispatching2::dialogue::InMemStorage<State>)]
|
||
|
enum State {
|
||
|
#[handler(handle_start)]
|
||
|
Start,
|
||
|
|
||
|
#[handler(handle_have_data)]
|
||
|
HaveData(String),
|
||
|
}
|
||
|
|
||
|
impl Default for State {
|
||
|
fn default() -> Self {
|
||
|
Self::Start
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async fn handle_start() -> Result<(), teloxide::RequestError> {
|
||
|
Ok(())
|
||
|
}
|
||
|
|
||
|
async fn handle_have_data() -> Result<(), teloxide::RequestError> {
|
||
|
Ok(())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[test]
|
||
|
#[cfg(feature = "macros")]
|
||
|
fn compile_test_generics() {
|
||
|
#[allow(dead_code)]
|
||
|
#[derive(DialogueState, Clone)]
|
||
|
#[out(Result<(), teloxide::RequestError>)]
|
||
|
#[store(teloxide::dispatching2::dialogue::InMemStorage<State<X>>)]
|
||
|
enum State<X: Clone + Send + Sync + 'static> {
|
||
|
#[handler(handle_start)]
|
||
|
Start,
|
||
|
|
||
|
#[handler(handle_have_data)]
|
||
|
HaveData(X),
|
||
|
}
|
||
|
|
||
|
impl<X: Clone + Send + Sync + 'static> Default for State<X> {
|
||
|
fn default() -> Self {
|
||
|
Self::Start
|
||
|
}
|
||
|
}
|
||
|
|
||
|
async fn handle_start() -> Result<(), teloxide::RequestError> {
|
||
|
Ok(())
|
||
|
}
|
||
|
|
||
|
async fn handle_have_data() -> Result<(), teloxide::RequestError> {
|
||
|
Ok(())
|
||
|
}
|
||
|
}
|