diff --git a/Cargo.toml b/Cargo.toml index 21a64b23..fce35c78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,43 +36,46 @@ macros = ["teloxide-macros"] nightly = [] # currently used for `README.md` tests and building docs for `docsrs` to add `This is supported on feature="..." only.` [dependencies] -serde_json = "1.0.55" -serde = { version = "1.0.114", features = ["derive"] } +teloxide-core = "0.1" -tokio = { version = "0.2.21", features = ["fs", "stream"] } -tokio-util = "0.3.1" +serde_json = "1.0" +serde = { version = "1.0", features = ["derive"] } -reqwest = { version = "0.10.6", features = ["json", "stream"] } -log = "0.4.8" +tokio = { version = "1.2", features = ["fs"] } +tokio-util = "0.6" +tokio-stream = "0.1" + +reqwest = { version = "0.11", features = ["json", "stream"] } +log = "0.4" lockfree = "0.5.1" -bytes = "0.5.5" -mime = "0.3.16" +bytes = "1.0" +mime = "0.3" -derive_more = "0.99.9" -thiserror = "1.0.20" -async-trait = "0.1.36" -futures = "0.3.5" -pin-project = "0.4.22" -serde_with_macros = "1.1.0" +derive_more = "0.99" +thiserror = "1.0" +async-trait = "0.1" +futures = "0.3" +pin-project = "1.0" +serde_with_macros = "1.4" -sqlx = { version = "0.4.0-beta.1", optional = true, default-features = false, features = [ +sqlx = { version = "0.5", optional = true, default-features = false, features = [ "runtime-tokio-native-tls", "macros", "sqlite", ] } -redis = { version = "0.16.0", optional = true } -serde_cbor = { version = "0.11.1", optional = true } -bincode = { version = "1.3.1", optional = true } -frunk = { version = "0.3.1", optional = true } +redis = { version = "0.16", optional = true } +serde_cbor = { version = "0.11", optional = true } +bincode = { version = "1.3", optional = true } +frunk = { version = "0.3", optional = true } teloxide-macros = { git = "https://github.com/teloxide/teloxide-macros", branch = "master", optional = true } [dev-dependencies] smart-default = "0.6.0" -rand = "0.7.3" +rand = "0.8.3" pretty_env_logger = "0.4.0" lazy_static = "1.4.0" -tokio = { version = "0.2.21", features = ["fs", "stream", "rt-threaded", "macros"] } +tokio = { version = "1.2.0", features = ["fs", "rt", "macros"] } [package.metadata.docs.rs] all-features = true diff --git a/rustfmt.toml b/rustfmt.toml index c61c5a92..38db4219 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,6 +1,6 @@ format_code_in_doc_comments = true wrap_comments = true format_strings = true -merge_imports = true +imports_granularity = "Crate" use_small_heuristics = "Max" use_field_init_shorthand = true diff --git a/src/bot/mod.rs b/src/bot/mod.rs index 28fe1a24..b936266f 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -126,7 +126,7 @@ pub(crate) fn sound_bot() -> ClientBuilder { ClientBuilder::new() .connect_timeout(connect_timeout) .timeout(Duration::from_secs(connect_timeout.as_secs() + timeout + 2)) - .tcp_nodelay_(true) + .tcp_nodelay(true) .default_headers(headers) } diff --git a/src/dispatching/dialogue/dialogue_dispatcher.rs b/src/dispatching/dialogue/dialogue_dispatcher.rs index 0e1f97b6..e555d84e 100644 --- a/src/dispatching/dialogue/dialogue_dispatcher.rs +++ b/src/dispatching/dialogue/dialogue_dispatcher.rs @@ -11,6 +11,7 @@ use tokio::sync::mpsc; use lockfree::map::Map; use std::sync::{Arc, Mutex}; +use tokio_stream::wrappers::UnboundedReceiverStream; /// A dispatcher of dialogues. /// @@ -84,7 +85,7 @@ where let handler = Arc::clone(&self.handler); let senders = Arc::clone(&self.senders); - tokio::spawn(rx.for_each(move |cx: UpdateWithCx| { + tokio::spawn(UnboundedReceiverStream::new(rx).for_each(move |cx: UpdateWithCx| { let storage = Arc::clone(&storage); let handler = Arc::clone(&handler); let senders = Arc::clone(&senders); @@ -137,7 +138,7 @@ where { let this = Arc::new(self); - updates + UnboundedReceiverStream::new(updates) .for_each(move |cx| { let this = Arc::clone(&this); let chat_id = cx.update.chat_id(); diff --git a/src/dispatching/repls/commands_repl.rs b/src/dispatching/repls/commands_repl.rs index d80138ca..cc90ad0c 100644 --- a/src/dispatching/repls/commands_repl.rs +++ b/src/dispatching/repls/commands_repl.rs @@ -10,6 +10,7 @@ use crate::{ }; use futures::StreamExt; use std::{fmt::Debug, future::Future, sync::Arc}; +use tokio_stream::wrappers::UnboundedReceiverStream; /// A [REPL] for commands. /// @@ -73,13 +74,16 @@ pub async fn commands_repl_with_listener<'a, Cmd, H, Fut, L, ListenerE, HandlerE Dispatcher::new(bot) .messages_handler(move |rx: DispatcherHandlerRx| { - rx.commands::(bot_name).for_each_concurrent(None, move |(cx, cmd)| { - let handler = Arc::clone(&handler); + UnboundedReceiverStream::new(rx).commands::(bot_name).for_each_concurrent( + None, + move |(cx, cmd)| { + let handler = Arc::clone(&handler); - async move { - handler(cx, cmd).await.log_on_error().await; - } - }) + async move { + handler(cx, cmd).await.log_on_error().await; + } + }, + ) }) .dispatch_with_listener( listener, diff --git a/src/dispatching/repls/repl.rs b/src/dispatching/repls/repl.rs index 9a50355f..877c6869 100644 --- a/src/dispatching/repls/repl.rs +++ b/src/dispatching/repls/repl.rs @@ -9,6 +9,7 @@ use crate::{ }; use futures::StreamExt; use std::{fmt::Debug, future::Future, sync::Arc}; +use tokio_stream::wrappers::UnboundedReceiverStream; /// A [REPL] for messages. /// @@ -57,7 +58,7 @@ where Dispatcher::new(bot) .messages_handler(|rx: DispatcherHandlerRx| { - rx.for_each_concurrent(None, move |message| { + UnboundedReceiverStream::new(rx).for_each_concurrent(None, move |message| { let handler = Arc::clone(&handler); async move { diff --git a/src/net/request.rs b/src/net/request.rs index e376c3fd..05f0af5e 100644 --- a/src/net/request.rs +++ b/src/net/request.rs @@ -52,7 +52,7 @@ where T: DeserializeOwned, { if response.status().is_server_error() { - tokio::time::delay_for(DELAY_ON_SERVER_ERROR).await; + tokio::time::sleep(DELAY_ON_SERVER_ERROR).await; } serde_json::from_str::>(