attempt to remove 'static lifetime in DispatcherHandlerRxExt::commands

This commit is contained in:
p0lunin 2020-02-23 11:21:46 +02:00
parent 32c2c041c9
commit c02af81dd1

View file

@ -16,13 +16,14 @@ pub trait DispatcherHandlerRxExt {
/// Extracts only commands with their arguments from this stream of
/// arbitrary messages.
fn commands<C>(
fn commands<C, N>(
self,
bot_name: &'static str,
bot_name: N,
) -> BoxStream<'static, (DispatcherHandlerCx<Message>, C, Vec<String>)>
where
Self: Stream<Item = DispatcherHandlerCx<Message>>,
C: BotCommand;
C: BotCommand,
N: Into<String>;
}
impl<T> DispatcherHandlerRxExt for T
@ -40,26 +41,25 @@ where
}))
}
fn commands<C>(
fn commands<C, N>(
self,
bot_name: &'static str,
bot_name: N,
) -> BoxStream<'static, (DispatcherHandlerCx<Message>, C, Vec<String>)>
where
Self: Stream<Item = DispatcherHandlerCx<Message>>,
C: BotCommand,
N: Into<String> + Send,
{
Box::pin(self.text_messages().filter_map(
move |(cx, text)| async move {
C::parse(&text, bot_name).map(|(command, args)| {
(
cx,
command,
args.into_iter()
.map(ToOwned::to_owned)
.collect::<Vec<String>>(),
)
})
},
))
Box::pin(self.text_messages().filter_map(|(cx, text)| async move {
C::parse(&text, &bot_name.into()).map(|(command, args)| {
(
cx,
command,
args.into_iter()
.map(ToOwned::to_owned)
.collect::<Vec<String>>(),
)
})
}))
}
}