append_field<_, T2, _, _> -> T2::up

This commit is contained in:
Temirkhan Myrzamadi 2020-07-26 04:09:57 +06:00
parent 6e7b13dfcc
commit 0c688b2bd2
5 changed files with 20 additions and 16 deletions

View file

@ -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?;

View file

@ -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))
}

View file

@ -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;

View file

@ -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
View 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 {}