From 0c688b2bd25dd34d03ba358b15da84650bd814bc Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Sun, 26 Jul 2020 04:09:57 +0600 Subject: [PATCH] append_field<_, T2, _, _> -> T2::up --- examples/dialogue_bot/src/transitions.rs | 4 ++-- src/append_field.rs | 12 ------------ src/lib.rs | 2 +- src/prelude.rs | 2 +- src/up_state.rs | 16 ++++++++++++++++ 5 files changed, 20 insertions(+), 16 deletions(-) delete mode 100644 src/append_field.rs create mode 100644 src/up_state.rs diff --git a/examples/dialogue_bot/src/transitions.rs b/examples/dialogue_bot/src/transitions.rs index 8819356d..8d08b526 100644 --- a/examples/dialogue_bot/src/transitions.rs +++ b/examples/dialogue_bot/src/transitions.rs @@ -21,7 +21,7 @@ async fn receive_full_name( match cx.update.text_owned() { Some(ans) => { 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?; @@ -35,7 +35,7 @@ async fn receive_age_state(state: ReceiveAgeState, cx: TransitionIn) -> Out { match cx.update.text().map(str::parse::) { Some(Ok(ans)) => { 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?; diff --git a/src/append_field.rs b/src/append_field.rs deleted file mode 100644 index 96aa71c5..00000000 --- a/src/append_field.rs +++ /dev/null @@ -1,12 +0,0 @@ -#[cfg(feature = "frunk")] -use frunk::{from_generic, generic::Generic, hlist::HAppender, into_generic}; - -#[cfg(feature = "frunk")] -pub fn append_field(src: T1, field: F) -> T2 -where - T1: Generic, - T2: Generic>::Output>, - T1Repr: HAppender, -{ - from_generic(into_generic(src).append(field)) -} diff --git a/src/lib.rs b/src/lib.rs index e23ffc9b..d30a19c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,6 @@ pub use errors::{ mod errors; mod net; -mod append_field; mod bot; pub mod dispatching; pub mod error_handlers; @@ -32,6 +31,7 @@ mod logging; pub mod prelude; pub mod requests; pub mod types; +mod up_state; pub mod utils; extern crate teloxide_macros; diff --git a/src/prelude.rs b/src/prelude.rs index 81183e1a..f61ac83c 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -15,7 +15,7 @@ pub use crate::{ }; #[cfg(feature = "frunk")] -pub use crate::append_field::append_field; +pub use crate::up_state::UpState; pub use tokio::sync::mpsc::UnboundedReceiver; diff --git a/src/up_state.rs b/src/up_state.rs new file mode 100644 index 00000000..37197c6d --- /dev/null +++ b/src/up_state.rs @@ -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(src: T1, field: F) -> Self + where + T1: Generic, + Self: Generic>::Output>, + T1Repr: HAppender, + { + from_generic(into_generic(src).append(field)) + } +} + +impl UpState for T2 {}