diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a97f3ab..5e273fcb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,6 +52,7 @@ jobs: - name: fmt uses: actions-rs/cargo@v1 + if: matrix.rust == 'nightly' with: command: fmt args: --all -- --check diff --git a/Cargo.toml b/Cargo.toml index d7e1e24c..472bdb86 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,4 +23,3 @@ serde_with_macros = "1.0.1" default = [] unstable-stream = [] # add streams to public API -never-type = [] # add never type (`!`) to punlic API diff --git a/src/dispatching/dispatchers/filter/error_policy.rs b/src/dispatching/dispatchers/filter/error_policy.rs index 98b1e0db..8d40bbb2 100644 --- a/src/dispatching/dispatchers/filter/error_policy.rs +++ b/src/dispatching/dispatchers/filter/error_policy.rs @@ -1,6 +1,5 @@ -#[cfg(not(feature = "never-type"))] -use std::convert::Infallible; -use std::{future::Future, pin::Pin}; +// Infallible used here instead of `!` to be compatible with rust <1.41 +use std::{convert::Infallible, future::Future, pin::Pin}; use async_trait::async_trait; @@ -73,28 +72,10 @@ where /// IgnoreSafe.handle_error(0); /// ``` /// -/// ## Note -/// Never type is not stabilized yet (see [`#35121`]) so all API that uses [`!`] -/// (including `impl ErrorPolicy for IgnoreSafe`) we hide under the -/// `never-type` cargo feature. -/// /// [`!`]: https://doc.rust-lang.org/std/primitive.never.html /// [`Infallible`]: std::convert::Infallible -/// [`#35121`]: https://github.com/rust-lang/rust/issues/35121 pub struct IgnoreSafe; -#[cfg(feature = "never-type")] -#[allow(unreachable_code)] -#[async_trait] -impl ErrorPolicy for IgnoreSafe { - async fn handle_error(&self, _: !) - where - !: 'async_trait, - { - } -} - -#[cfg(not(feature = "never-type"))] #[allow(unreachable_code)] #[async_trait] impl ErrorPolicy for IgnoreSafe { diff --git a/src/dispatching/dispatchers/filter/mod.rs b/src/dispatching/dispatchers/filter/mod.rs index e86f1894..89fb093d 100644 --- a/src/dispatching/dispatchers/filter/mod.rs +++ b/src/dispatching/dispatchers/filter/mod.rs @@ -75,8 +75,8 @@ type FiltersAndHandlers<'a, T, E> = Vec>; /// // with error policy that just ignores all errors (that can't ever happen) /// let mut dp = FilterDispatcher::::new(|_| async {}) /// // Add 'handler' that will handle all messages sent to the bot -/// .message_handler(true, |mes: Message| { -/// async move { println!("New message: {:?}", mes) } +/// .message_handler(true, |mes: Message| async move { +/// println!("New message: {:?}", mes) /// }) /// // Add 'handler' that will handle all /// // messages edited in chat with the bot @@ -318,16 +318,12 @@ mod tests { let counter2 = &AtomicI32::new(0); let mut dp = FilterDispatcher::::new(|_| async {}) - .message_handler(true, |_mes: Message| { - async move { - counter.fetch_add(1, Ordering::SeqCst); - } + .message_handler(true, |_mes: Message| async move { + counter.fetch_add(1, Ordering::SeqCst); }) - .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; diff --git a/src/dispatching/updater.rs b/src/dispatching/updater.rs index 64653c96..fdf4aaf1 100644 --- a/src/dispatching/updater.rs +++ b/src/dispatching/updater.rs @@ -136,19 +136,17 @@ where } pub fn polling<'a>(bot: &'a Bot) -> impl Updater + 'a { - let stream = stream::unfold((bot, 0), |(bot, mut offset)| { - async move { - let updates = match bot.get_updates().offset(offset).send().await { - Ok(updates) => { - if let Some(upd) = updates.last() { - offset = upd.id + 1; - } - updates.into_iter().map(Ok).collect::>() + let stream = stream::unfold((bot, 0), |(bot, mut offset)| async move { + let updates = match bot.get_updates().offset(offset).send().await { + Ok(updates) => { + if let Some(upd) = updates.last() { + offset = upd.id + 1; } - Err(err) => vec![Err(err)], - }; - Some((stream::iter(updates), (bot, offset))) - } + updates.into_iter().map(Ok).collect::>() + } + Err(err) => vec![Err(err)], + }; + Some((stream::iter(updates), (bot, offset))) }) .flatten(); diff --git a/src/network/download.rs b/src/network/download.rs index 47061b6f..4ff6c794 100644 --- a/src/network/download.rs +++ b/src/network/download.rs @@ -42,13 +42,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, } })) }