Merge pull request #124 from teloxide/fix-fmt

Fix rustfmt
This commit is contained in:
Temirkhan Myrzamadi 2020-01-05 02:41:55 +06:00 committed by GitHub
commit ae0454a716
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 98 additions and 108 deletions

View file

@ -186,81 +186,79 @@ impl<'a, HandlerE, Eh> FilterDispatcher<'a, HandlerE, Eh> {
Eh: ErrorHandler<Either<UpdaterE, HandlerE>>,
{
updater
.for_each_concurrent(None, |res| {
async {
let Update { kind, id } = match res {
Ok(upd) => upd,
Err(err) => {
self.error_handler
.handle_error(Either::Left(err))
.await;
return;
}
};
.for_each_concurrent(None, |res| async {
let Update { kind, id } = match res {
Ok(upd) => upd,
Err(err) => {
self.error_handler
.handle_error(Either::Left(err))
.await;
return;
}
};
log::debug!(
"Handled update#{id:?}: {kind:?}",
id = id,
kind = kind
);
log::debug!(
"Handled update#{id:?}: {kind:?}",
id = id,
kind = kind
);
match kind {
UpdateKind::Message(mes) => {
Self::handle(
mes,
&self.message_handlers,
&self.error_handler,
)
.await
}
UpdateKind::EditedMessage(mes) => {
Self::handle(
mes,
&self.edited_message_handlers,
&self.error_handler,
)
.await;
}
UpdateKind::ChannelPost(post) => {
Self::handle(
post,
&self.channel_post_handlers,
&self.error_handler,
)
.await;
}
UpdateKind::EditedChannelPost(post) => {
Self::handle(
post,
&self.edited_channel_post_handlers,
&self.error_handler,
)
.await;
}
UpdateKind::InlineQuery(query) => {
Self::handle(
query,
&self.inline_query_handlers,
&self.error_handler,
)
.await;
}
UpdateKind::ChosenInlineResult(result) => {
Self::handle(
result,
&self.chosen_inline_result_handlers,
&self.error_handler,
)
.await;
}
UpdateKind::CallbackQuery(callback) => {
Self::handle(
callback,
&self.callback_query_handlers,
&self.error_handler,
)
.await;
}
match kind {
UpdateKind::Message(mes) => {
Self::handle(
mes,
&self.message_handlers,
&self.error_handler,
)
.await
}
UpdateKind::EditedMessage(mes) => {
Self::handle(
mes,
&self.edited_message_handlers,
&self.error_handler,
)
.await;
}
UpdateKind::ChannelPost(post) => {
Self::handle(
post,
&self.channel_post_handlers,
&self.error_handler,
)
.await;
}
UpdateKind::EditedChannelPost(post) => {
Self::handle(
post,
&self.edited_channel_post_handlers,
&self.error_handler,
)
.await;
}
UpdateKind::InlineQuery(query) => {
Self::handle(
query,
&self.inline_query_handlers,
&self.error_handler,
)
.await;
}
UpdateKind::ChosenInlineResult(result) => {
Self::handle(
result,
&self.chosen_inline_result_handlers,
&self.error_handler,
)
.await;
}
UpdateKind::CallbackQuery(callback) => {
Self::handle(
callback,
&self.callback_query_handlers,
&self.error_handler,
)
.await;
}
}
})
@ -310,17 +308,13 @@ mod tests {
let counter2 = &AtomicI32::new(0);
let mut dp = FilterDispatcher::<Infallible, _>::new(|_| async {})
.message_handler(true, |_mes: Message| {
async move {
counter.fetch_add(1, Ordering::SeqCst);
Ok::<_, Infallible>(())
}
.message_handler(true, |_mes: Message| async move {
counter.fetch_add(1, Ordering::SeqCst);
Ok::<_, Infallible>(())
})
.message_handler(true, |_mes: Message| {
async move {
counter2.fetch_add(1, Ordering::SeqCst);
Ok::<_, Infallible>(())
}
.message_handler(true, |_mes: Message| async move {
counter2.fetch_add(1, Ordering::SeqCst);
Ok::<_, Infallible>(())
});
dp.dispatch(one_message_updater()).await;

View file

@ -146,25 +146,23 @@ pub fn polling(
stream::unfold(
(allowed_updates, bot, 0),
move |(mut allowed_updates, bot, mut offset)| {
async move {
let mut req = bot.get_updates().offset(offset);
req.timeout = timeout;
req.limit = limit;
req.allowed_updates = allowed_updates.take();
move |(mut allowed_updates, bot, mut offset)| async move {
let mut req = bot.get_updates().offset(offset);
req.timeout = timeout;
req.limit = limit;
req.allowed_updates = allowed_updates.take();
let updates = match req.send().await {
Err(err) => vec![Err(err)],
Ok(updates) => {
if let Some(upd) = updates.last() {
offset = upd.id + 1;
}
updates.into_iter().map(Ok).collect::<Vec<_>>()
let updates = match req.send().await {
Err(err) => vec![Err(err)],
Ok(updates) => {
if let Some(upd) = updates.last() {
offset = upd.id + 1;
}
};
updates.into_iter().map(Ok).collect::<Vec<_>>()
}
};
Some((stream::iter(updates), (allowed_updates, bot, offset)))
}
Some((stream::iter(updates), (allowed_updates, bot, offset)))
},
)
.flatten()

View file

@ -39,13 +39,11 @@ pub async fn download_file_stream(
.await?
.error_for_status()?;
Ok(futures::stream::unfold(res, |mut res| {
async {
match res.chunk().await {
Err(err) => Some((Err(err), res)),
Ok(Some(c)) => Some((Ok(c), res)),
Ok(None) => None,
}
Ok(futures::stream::unfold(res, |mut res| async {
match res.chunk().await {
Err(err) => Some((Err(err), res)),
Ok(Some(c)) => Some((Ok(c), res)),
Ok(None) => None,
}
}))
}

View file

@ -49,7 +49,7 @@ use serde::{Deserialize, Serialize};
/// pre-formatted fixed-width code block written in the Rust programming
/// language ```
/// ````
///
///
/// Please note:
/// - Any character between 1 and 126 inclusively can be escaped anywhere with a
/// preceding '\' character, in which case it is treated as an ordinary
@ -110,7 +110,7 @@ use serde::{Deserialize, Serialize};
/// pre-formatted fixed-width code block written in the Rust programming
/// language ```
/// ````
///
///
/// Please note:
/// - Entities must not be nested, use parse mode [`MarkdownV2`] instead.
/// - There is no way to specify underline and strikethrough entities, use parse