Simplified Handler::new
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
use crate::prelude::*;
|
||||
use futures::future::BoxFuture;
|
||||
use std::{future::Future, sync::Arc};
|
||||
use std::sync::Arc;
|
||||
use teloxide::types::MessageId;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
@ -43,17 +43,20 @@ pub type PackagedHandler<T> = Arc<Mutex<Handler<T>>>;
|
||||
impl<T> Handler<T> {
|
||||
/// Convinience method to convert a simple async function and a previous message into PackagedHandler
|
||||
#[inline]
|
||||
pub fn new<H, F>(f: H, previous: impl Into<MessageIds>) -> PackagedHandler<T>
|
||||
pub fn new<H>(f: H, previous: impl Into<MessageIds>) -> PackagedHandler<T>
|
||||
where
|
||||
H: FnOnce(Throttle<Bot>, Message, DatabaseConnection, MainDialogue, T) -> F
|
||||
H: FnOnce(
|
||||
Throttle<Bot>,
|
||||
Message,
|
||||
DatabaseConnection,
|
||||
MainDialogue,
|
||||
T,
|
||||
) -> BoxFuture<'static, crate::Result<()>>
|
||||
+ Send
|
||||
+ 'static,
|
||||
F: Future<Output = crate::Result<()>> + Send + 'static,
|
||||
{
|
||||
let handler = Self {
|
||||
func: Some(Box::new(|bot, msg, db, dialogue, val| {
|
||||
Box::pin(f(bot, msg, db, dialogue, val))
|
||||
})),
|
||||
func: Some(Box::new(f)),
|
||||
previous: previous.into(),
|
||||
};
|
||||
Arc::new(Mutex::new(handler))
|
||||
|
Reference in New Issue
Block a user