Merge pull request #950 from teloxide/fixup-build

Fix CI
This commit is contained in:
Tima Kinsart 2023-10-05 15:59:42 +00:00 committed by GitHub
commit 9b593ddb54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 113 additions and 45 deletions

View file

@ -24,7 +24,9 @@ env:
# - **/README.md # - **/README.md
# - **/src/lib.rs # - **/src/lib.rs
# - down below in a matrix # - down below in a matrix
rust_msrv: 1.65.0 # - `Cargo.toml`
# - **/CHANGELOG.md
rust_msrv: 1.68.0
CI: 1 CI: 1
@ -87,7 +89,7 @@ jobs:
toolchain: nightly-2023-09-27 toolchain: nightly-2023-09-27
features: "--features full nightly" features: "--features full nightly"
- rust: msrv - rust: msrv
toolchain: 1.65.0 toolchain: 1.68.0
features: "--features full" features: "--features full"
steps: steps:

View file

@ -7,11 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## unreleased ## unreleased
### Added ### Added
- Add `MessageToCopyNotFound` error to `teloxide::errors::ApiError` ([PR 917](https://github.com/teloxide/teloxide/pull/917)) - Add `MessageToCopyNotFound` error to `teloxide::errors::ApiError` ([PR 917](https://github.com/teloxide/teloxide/pull/917))
### Fixed ### Fixed
- Use `UserId` instead of `i64` for `user_id` in `html::user_mention` and `markdown::user_mention` ([PR 896](https://github.com/teloxide/teloxide/pull/896)) - Use `UserId` instead of `i64` for `user_id` in `html::user_mention` and `markdown::user_mention` ([PR 896](https://github.com/teloxide/teloxide/pull/896))
- Greatly improved the speed of graceful shutdown (`^C`) ([PR 938](https://github.com/teloxide/teloxide/pull/938)) - Greatly improved the speed of graceful shutdown (`^C`) ([PR 938](https://github.com/teloxide/teloxide/pull/938))
### Changed
- MSRV (Minimal Supported Rust Version) was bumped from `1.64.0` to `1.68.0` ([PR 950][https://github.com/teloxide/teloxide/pull/950])
### Removed ### Removed
- `UpdateListener::timeout_hint` and related APIs ([PR 938](https://github.com/teloxide/teloxide/pull/938)) - `UpdateListener::timeout_hint` and related APIs ([PR 938](https://github.com/teloxide/teloxide/pull/938))

View file

@ -5,7 +5,7 @@ resolver = "2"
# The settings below will be applied to all crates in the workspace # The settings below will be applied to all crates in the workspace
[workspace.package] [workspace.package]
# MSRV (minimal supported Rust version). # MSRV (minimal supported Rust version).
rust-version = "1.65" rust-version = "1.68"
edition = "2021" edition = "2021"
license = "MIT" license = "MIT"

View file

@ -58,7 +58,7 @@ $ set TELOXIDE_TOKEN=<Your token here>
$ $env:TELOXIDE_TOKEN=<Your token here> $ $env:TELOXIDE_TOKEN=<Your token here>
``` ```
4. Make sure that your Rust compiler is up to date (`teloxide` currently requires rustc at least version 1.65): 4. Make sure that your Rust compiler is up to date (`teloxide` currently requires rustc at least version 1.68):
```bash ```bash
# If you're using stable # If you're using stable
$ rustup update stable $ rustup update stable

View file

@ -54,7 +54,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `CallbackGame`, `ForumTopicClosed`, `ForumTopicReopened`, `GeneralForumTopicHidden`, `GeneralForumTopicUnhidden` and `WriteAccessAllowed` structures - `CallbackGame`, `ForumTopicClosed`, `ForumTopicReopened`, `GeneralForumTopicHidden`, `GeneralForumTopicUnhidden` and `WriteAccessAllowed` structures
are now defined as named (`struct S {}`) instead of unit (`struct S;`) in order to fix their deserialization ([#876][pr876]) are now defined as named (`struct S {}`) instead of unit (`struct S;`) in order to fix their deserialization ([#876][pr876])
- `Download` now uses GAT feature on the `Fut` and `Err` associated types, instead of a lifetime on the whole trait ([#885][pr885]) - `Download` now uses GAT feature on the `Fut` and `Err` associated types, instead of a lifetime on the whole trait ([#885][pr885])
- MSRV (Minimal Supported Rust Version) was bumped from `1.64.0` to `1.65.0`
- Renamed `ForumTopic::message_thread_id` into `thread_id` ([#887][pr887]) - Renamed `ForumTopic::message_thread_id` into `thread_id` ([#887][pr887])
- `ForumTopic::thread_id` and `Message::thread_id` now use `ThreadId` instead of `i32` ([#887][pr887]) - `ForumTopic::thread_id` and `Message::thread_id` now use `ThreadId` instead of `i32` ([#887][pr887])
- `message_thread_id` method parameters now use `ThreadId` instead of `i32` ([#887][pr887]) - `message_thread_id` method parameters now use `ThreadId` instead of `i32` ([#887][pr887])
@ -67,12 +66,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Use `u32` for sizes and `Seconds` for timespans in `InlineQueryResult*` ([#887][pr887]) - Use `u32` for sizes and `Seconds` for timespans in `InlineQueryResult*` ([#887][pr887])
- `SendGame::reply_to_message_id`, `SendSticker::reply_to_message_id` and `SendInvoice::reply_to_message_id` now use `MessageId` instead of `i32` ([#887][pr887]) - `SendGame::reply_to_message_id`, `SendSticker::reply_to_message_id` and `SendInvoice::reply_to_message_id` now use `MessageId` instead of `i32` ([#887][pr887])
- Use `UpdateId` for `Update::id` ([#892][pr892]) - Use `UpdateId` for `Update::id` ([#892][pr892])
- MSRV (Minimal Supported Rust Version) was bumped from `1.64.0` to `1.68.0` ([#950][pr950])
[pr852]: https://github.com/teloxide/teloxide/pull/853 [pr852]: https://github.com/teloxide/teloxide/pull/853
[pr859]: https://github.com/teloxide/teloxide/pull/859 [pr859]: https://github.com/teloxide/teloxide/pull/859
[pr876]: https://github.com/teloxide/teloxide/pull/876 [pr876]: https://github.com/teloxide/teloxide/pull/876
[pr885]: https://github.com/teloxide/teloxide/pull/885 [pr885]: https://github.com/teloxide/teloxide/pull/885
[pr892]: https://github.com/teloxide/teloxide/pull/892 [pr892]: https://github.com/teloxide/teloxide/pull/892
[pr950]: https://github.com/teloxide/teloxide/pull/950
### Deprecated ### Deprecated

View file

@ -31,7 +31,7 @@ native-tls = ["reqwest/native-tls"]
nightly = [] nightly = []
# Throttling bot adaptor # Throttling bot adaptor
throttle = ["vecrem", "tokio/macros"] throttle = ["vecrem"]
# Trace bot adaptor # Trace bot adaptor
trace_adaptor = [] trace_adaptor = []
@ -55,7 +55,11 @@ tokio = { version = "1.12.0", features = ["fs"] }
tokio-util = { version = "0.7.0", features = ["codec"] } tokio-util = { version = "0.7.0", features = ["codec"] }
pin-project = "1.0.12" pin-project = "1.0.12"
bytes = "1.0.0" bytes = "1.0.0"
reqwest = { version = "0.11.10", features = ["json", "stream", "multipart"], default-features = false } reqwest = { version = "0.11.10", features = [
"json",
"stream",
"multipart",
], default-features = false }
url = { version = "2", features = ["serde"] } url = { version = "2", features = ["serde"] }
log = "0.4" log = "0.4"
@ -81,7 +85,12 @@ vecrem = { version = "0.1", optional = true }
[dev-dependencies] [dev-dependencies]
pretty_env_logger = "0.4" pretty_env_logger = "0.4"
tokio = { version = "1.8.0", features = ["fs", "macros", "macros", "rt-multi-thread"] } tokio = { version = "1.8.0", features = [
"fs",
"macros",
"macros",
"rt-multi-thread",
] }
cool_asserts = "2.0.3" cool_asserts = "2.0.3"
xshell = "0.2" xshell = "0.2"
@ -102,9 +111,9 @@ cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
tag-prefix = "core-" tag-prefix = "core-"
enable-features = ["full"] enable-features = ["full"]
pre-release-replacements = [ pre-release-replacements = [
{file="README.md", search="teloxide-core = \"[^\"]+\"", replace="teloxide-core = \"{{version}}\""}, { file = "README.md", search = "teloxide-core = \"[^\"]+\"", replace = "teloxide-core = \"{{version}}\"" },
{file="src/lib.rs", search="teloxide-core = \"[^\"]+\"", replace="teloxide-core = \"{{version}}\""}, { file = "src/lib.rs", search = "teloxide-core = \"[^\"]+\"", replace = "teloxide-core = \"{{version}}\"" },
{file="CHANGELOG.md", search="## unreleased", replace="## unreleased\n\n## {{version}} - {{date}}", exactly=1}, { file = "CHANGELOG.md", search = "## unreleased", replace = "## unreleased\n\n## {{version}} - {{date}}", exactly = 1 },
] ]
[[example]] [[example]]
@ -118,4 +127,9 @@ doc-scrape-examples = true
[[example]] [[example]]
name = "erased" name = "erased"
required-features = ["tokio/macros", "tokio/rt-multi-thread", "erased", "trace_adaptor"] required-features = [
"tokio/macros",
"tokio/rt-multi-thread",
"erased",
"trace_adaptor",
]

View file

@ -27,7 +27,7 @@
```toml ```toml
teloxide-core = "0.9" teloxide-core = "0.9"
``` ```
_Compiler support: requires rustc 1.65+_. _Compiler support: requires rustc 1.68+_.
[`teloxide`]: https://docs.rs/teloxide [`teloxide`]: https://docs.rs/teloxide
[Telegram Bot API]: https://core.telegram.org/bots/api [Telegram Bot API]: https://core.telegram.org/bots/api

View file

@ -1,8 +1,11 @@
use std::{ use std::{
collections::{hash_map::Entry, HashMap, VecDeque}, collections::{hash_map::Entry, HashMap, VecDeque},
pin::pin,
time::{Duration, Instant}, time::{Duration, Instant},
}; };
use either::Either;
use futures::{future, FutureExt as _};
use tokio::sync::{mpsc, mpsc::error::TryRecvError, oneshot::Sender}; use tokio::sync::{mpsc, mpsc::error::TryRecvError, oneshot::Sender};
use vecrem::VecExt; use vecrem::VecExt;
@ -129,17 +132,19 @@ pub(super) async fn worker<B>(
answer_info(&mut info_rx, &mut limits); answer_info(&mut info_rx, &mut limits);
loop { loop {
tokio::select! { let res = future::select(
freeze_until = freeze_rx.recv() => { pin!(freeze_rx.recv()),
freeze( pin!(read_from_rx(&mut rx, &mut queue, &mut rx_is_closed)),
&mut freeze_rx,
slow_mode.as_mut(),
&bot,
freeze_until
) )
.await; .map(either)
}, .await
() = read_from_rx(&mut rx, &mut queue, &mut rx_is_closed) => break, .map_either(|l| l.0, |r| r.0);
match res {
Either::Left(freeze_until) => {
freeze(&mut freeze_rx, slow_mode.as_mut(), &bot, freeze_until).await;
}
Either::Right(()) => break,
} }
} }
//debug_assert_eq!(queue.capacity(), limits.messages_per_sec_overall as usize); //debug_assert_eq!(queue.capacity(), limits.messages_per_sec_overall as usize);
@ -292,6 +297,8 @@ fn answer_info(rx: &mut mpsc::Receiver<InfoMessage>, limits: &mut Limits) {
} }
} }
// FIXME: https://github.com/rust-lang/rust-clippy/issues/11610
#[allow(clippy::needless_pass_by_ref_mut)]
async fn freeze( async fn freeze(
rx: &mut mpsc::Receiver<FreezeUntil>, rx: &mut mpsc::Receiver<FreezeUntil>,
mut slow_mode: Option<&mut HashMap<ChatIdHash, (Duration, Instant)>>, mut slow_mode: Option<&mut HashMap<ChatIdHash, (Duration, Instant)>>,
@ -372,6 +379,13 @@ async fn read_from_rx<T>(rx: &mut mpsc::Receiver<T>, queue: &mut Vec<T>, rx_is_c
} }
} }
fn either<L, R>(x: future::Either<L, R>) -> Either<L, R> {
match x {
future::Either::Left(l) => Either::Left(l),
future::Either::Right(r) => Either::Right(r),
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
#[tokio::test] #[tokio::test]

View file

@ -7,7 +7,7 @@
//!```toml //!```toml
//! teloxide-core = "0.9" //! teloxide-core = "0.9"
//! ``` //! ```
//! _Compiler support: requires rustc 1.65+_. //! _Compiler support: requires rustc 1.68+_.
//! //!
//! ``` //! ```
//! # async { //! # async {

View file

@ -9,14 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Now you can use `#[command(command_separator="sep")]` (default is a whitespace character) to set the separator between command and its arguments ([issue #897](https://github.com/teloxide/teloxide/issues/897)) - Now you can use `#[command(command_separator="sep")]` (default is a whitespace character) to set the separator between command and its arguments ([issue #897](https://github.com/teloxide/teloxide/issues/897))
- Now you can use `/// doc comment` for the command help message ([PR #861](https://github.com/teloxide/teloxide/pull/861)).
- Now you can use `#[command(hide)]` to hide a command from the help message ([PR #862](https://github.com/teloxide/teloxide/pull/862))
### Fixed ### Fixed
- Fix `split` parser for tuple variants with len < 2 ([issue #834](https://github.com/teloxide/teloxide/issues/834)) - Fix `split` parser for tuple variants with len < 2 ([issue #834](https://github.com/teloxide/teloxide/issues/834))
### Added ### Changed
- Now you can use `/// doc comment` for the command help message ([PR #861](https://github.com/teloxide/teloxide/pull/861)).
- Now you can use `#[command(hide)]` to hide a command from the help message ([PR #862](https://github.com/teloxide/teloxide/pull/862)) - MSRV (Minimal Supported Rust Version) was bumped from `1.64.0` to `1.68.0` ([PR 950][https://github.com/teloxide/teloxide/pull/950])
### Deprecated ### Deprecated

View file

@ -4,6 +4,7 @@ version = "0.12.2"
description = "An elegant Telegram bots framework for Rust" description = "An elegant Telegram bots framework for Rust"
rust-version.workspace = true rust-version.workspace = true
edition.workspace = true edition.workspace = true
license.workspace = true license.workspace = true
homepage.workspace = true homepage.workspace = true
@ -37,7 +38,9 @@ native-tls = ["teloxide-core/native-tls"]
rustls = ["teloxide-core/rustls"] rustls = ["teloxide-core/rustls"]
auto-send = ["teloxide-core/auto_send"] auto-send = ["teloxide-core/auto_send"]
throttle = ["teloxide-core/throttle"] throttle = ["teloxide-core/throttle"]
cache-me = ["teloxide-core/cache_me"] # FIXME: why teloxide and core use - _ differently? cache-me = [
"teloxide-core/cache_me",
] # FIXME: why teloxide and core use - _ differently?
trace-adaptor = ["teloxide-core/trace_adaptor"] trace-adaptor = ["teloxide-core/trace_adaptor"]
erased = ["teloxide-core/erased"] erased = ["teloxide-core/erased"]
@ -94,6 +97,7 @@ futures = "0.3.15"
pin-project = "1.0" pin-project = "1.0"
serde_with_macros = "1.4" serde_with_macros = "1.4"
aquamarine = "0.1.11" aquamarine = "0.1.11"
either = "1.9.0"
sqlx = { version = "0.6", optional = true, default-features = false, features = [ sqlx = { version = "0.6", optional = true, default-features = false, features = [
"macros", "macros",
@ -131,8 +135,8 @@ cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
tag-prefix = "" tag-prefix = ""
enable-features = ["full"] enable-features = ["full"]
pre-release-replacements = [ pre-release-replacements = [
{file="../../README.md", search="teloxide = \\{ version = \"[^\"]+\"", replace="teloxide = { version = \"{{version}}\""}, { file = "../../README.md", search = "teloxide = \\{ version = \"[^\"]+\"", replace = "teloxide = { version = \"{{version}}\"" },
{file="../../CHANGELOG.md", search="## unreleased", replace="## unreleased\n\n## {{version}} - {{date}}", exactly=1}, { file = "../../CHANGELOG.md", search = "## unreleased", replace = "## unreleased\n\n## {{version}} - {{date}}", exactly = 1 },
] ]
[[test]] [[test]]
@ -165,7 +169,12 @@ required-features = ["macros", "ctrlc_handler"]
[[example]] [[example]]
name = "db_remember" name = "db_remember"
required-features = ["sqlite-storage", "redis-storage", "bincode-serializer", "macros"] required-features = [
"sqlite-storage",
"redis-storage",
"bincode-serializer",
"macros",
]
[[example]] [[example]]
name = "dialogue" name = "dialogue"

View file

@ -10,7 +10,12 @@ use crate::{
}; };
use dptree::di::{DependencyMap, DependencySupplier}; use dptree::di::{DependencyMap, DependencySupplier};
use futures::{future::BoxFuture, stream::FuturesUnordered, StreamExt}; use either::Either;
use futures::{
future::{self, BoxFuture},
stream::FuturesUnordered,
FutureExt as _, StreamExt as _,
};
use tokio_stream::wrappers::ReceiverStream; use tokio_stream::wrappers::ReceiverStream;
use std::{ use std::{
@ -19,6 +24,7 @@ use std::{
future::Future, future::Future,
hash::Hash, hash::Hash,
ops::{ControlFlow, Deref}, ops::{ControlFlow, Deref},
pin::pin,
sync::{ sync::{
atomic::{AtomicBool, AtomicU32, Ordering}, atomic::{AtomicBool, AtomicU32, Ordering},
Arc, Arc,
@ -321,12 +327,18 @@ where
loop { loop {
self.remove_inactive_workers_if_needed().await; self.remove_inactive_workers_if_needed().await;
tokio::select! { let res = future::select(stream.next(), pin!(self.state.wait_for_changes()))
upd = stream.next() => match upd { .map(either)
None => break, .await
.map_either(|l| l.0, |r| r.0);
match res {
Either::Left(upd) => match upd {
Some(upd) => self.process_update(upd, &update_listener_error_handler).await, Some(upd) => self.process_update(upd, &update_listener_error_handler).await,
None => break,
}, },
() = self.state.wait_for_changes() => if self.state.is_shutting_down() { Either::Right(()) => {
if self.state.is_shutting_down() {
if let Some(token) = stop_token.take() { if let Some(token) = stop_token.take() {
log::debug!("Start shutting down dispatching..."); log::debug!("Start shutting down dispatching...");
token.stop(); token.stop();
@ -335,6 +347,7 @@ where
} }
} }
} }
}
self.workers self.workers
.drain() .drain()
@ -578,6 +591,12 @@ async fn handle_update<Err>(
} }
} }
fn either<L, R>(x: future::Either<L, R>) -> Either<L, R> {
match x {
future::Either::Left(l) => Either::Left(l),
future::Either::Right(r) => Either::Right(r),
}
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use std::convert::Infallible; use std::convert::Infallible;