mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 17:52:12 +01:00
append_field<_, T2, _, _> -> T2::up
This commit is contained in:
parent
6e7b13dfcc
commit
0c688b2bd2
5 changed files with 20 additions and 16 deletions
|
@ -21,7 +21,7 @@ async fn receive_full_name(
|
||||||
match cx.update.text_owned() {
|
match cx.update.text_owned() {
|
||||||
Some(ans) => {
|
Some(ans) => {
|
||||||
cx.answer_str("How old are you?").await?;
|
cx.answer_str("How old are you?").await?;
|
||||||
next(append_field::<_, ReceiveAgeState, _, _>(state, ans))
|
next(ReceiveAgeState::up(state, ans))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
cx.answer_str("Send me a text message.").await?;
|
cx.answer_str("Send me a text message.").await?;
|
||||||
|
@ -35,7 +35,7 @@ async fn receive_age_state(state: ReceiveAgeState, cx: TransitionIn) -> Out {
|
||||||
match cx.update.text().map(str::parse::<u8>) {
|
match cx.update.text().map(str::parse::<u8>) {
|
||||||
Some(Ok(ans)) => {
|
Some(Ok(ans)) => {
|
||||||
cx.answer_str("What's your location?").await?;
|
cx.answer_str("What's your location?").await?;
|
||||||
next(append_field::<_, ReceiveLocationState, _, _>(state, ans))
|
next(ReceiveLocationState::up(state, ans))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
cx.answer_str("Send me a number.").await?;
|
cx.answer_str("Send me a number.").await?;
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
#[cfg(feature = "frunk")]
|
|
||||||
use frunk::{from_generic, generic::Generic, hlist::HAppender, into_generic};
|
|
||||||
|
|
||||||
#[cfg(feature = "frunk")]
|
|
||||||
pub fn append_field<T1, T2, T1Repr, F>(src: T1, field: F) -> T2
|
|
||||||
where
|
|
||||||
T1: Generic<Repr = T1Repr>,
|
|
||||||
T2: Generic<Repr = <T1Repr as HAppender<F>>::Output>,
|
|
||||||
T1Repr: HAppender<F>,
|
|
||||||
{
|
|
||||||
from_generic(into_generic(src).append(field))
|
|
||||||
}
|
|
|
@ -24,7 +24,6 @@ pub use errors::{
|
||||||
mod errors;
|
mod errors;
|
||||||
mod net;
|
mod net;
|
||||||
|
|
||||||
mod append_field;
|
|
||||||
mod bot;
|
mod bot;
|
||||||
pub mod dispatching;
|
pub mod dispatching;
|
||||||
pub mod error_handlers;
|
pub mod error_handlers;
|
||||||
|
@ -32,6 +31,7 @@ mod logging;
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
pub mod requests;
|
pub mod requests;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
mod up_state;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
|
|
||||||
extern crate teloxide_macros;
|
extern crate teloxide_macros;
|
||||||
|
|
|
@ -15,7 +15,7 @@ pub use crate::{
|
||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "frunk")]
|
#[cfg(feature = "frunk")]
|
||||||
pub use crate::append_field::append_field;
|
pub use crate::up_state::UpState;
|
||||||
|
|
||||||
pub use tokio::sync::mpsc::UnboundedReceiver;
|
pub use tokio::sync::mpsc::UnboundedReceiver;
|
||||||
|
|
||||||
|
|
16
src/up_state.rs
Normal file
16
src/up_state.rs
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
#[cfg(feature = "frunk")]
|
||||||
|
use frunk::{from_generic, generic::Generic, hlist::HAppender, into_generic};
|
||||||
|
|
||||||
|
#[cfg(feature = "frunk")]
|
||||||
|
pub trait UpState: Sized {
|
||||||
|
fn up<T1, T1Repr, F>(src: T1, field: F) -> Self
|
||||||
|
where
|
||||||
|
T1: Generic<Repr = T1Repr>,
|
||||||
|
Self: Generic<Repr = <T1Repr as HAppender<F>>::Output>,
|
||||||
|
T1Repr: HAppender<F>,
|
||||||
|
{
|
||||||
|
from_generic(into_generic(src).append(field))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T2> UpState for T2 {}
|
Loading…
Reference in a new issue