From a001bb8c97b9542ba6783430bc897ab42ebf8e58 Mon Sep 17 00:00:00 2001 From: Igor Katson Date: Tue, 27 Feb 2024 08:14:39 +0000 Subject: [PATCH] Shorten Pin Pin>> + Send>> { + pub fn with_config(mut config: DhtConfig) -> BoxFuture<'static, anyhow::Result>> { async move { let socket = match config.listen_addr { Some(addr) => UdpSocket::bind(addr) diff --git a/crates/dht/src/persistence.rs b/crates/dht/src/persistence.rs index 0c73b05..05bff6f 100644 --- a/crates/dht/src/persistence.rs +++ b/crates/dht/src/persistence.rs @@ -1,6 +1,7 @@ // TODO: this now stores only the routing table, but we also need AT LEAST the same socket address... -use futures::{Future, FutureExt}; +use futures::future::BoxFuture; +use futures::FutureExt; use librqbit_core::directories::get_configuration_directory; use librqbit_core::spawn_utils::spawn_with_cancel; use serde::{Deserialize, Serialize}; @@ -8,7 +9,6 @@ use std::fs::OpenOptions; use std::io::{BufReader, BufWriter}; use std::net::SocketAddr; use std::path::{Path, PathBuf}; -use std::pin::Pin; use std::time::Duration; use tokio_util::sync::CancellationToken; @@ -81,7 +81,7 @@ impl PersistentDht { pub fn create( config: Option, cancellation_token: Option, - ) -> Pin> + Send>> { + ) -> BoxFuture<'static, anyhow::Result> { async move { let mut config = config.unwrap_or_default(); let config_filename = match config.config_filename.take() { diff --git a/crates/librqbit/src/http_api.rs b/crates/librqbit/src/http_api.rs index 806ba4c..d710b22 100644 --- a/crates/librqbit/src/http_api.rs +++ b/crates/librqbit/src/http_api.rs @@ -3,12 +3,12 @@ use axum::body::Bytes; use axum::extract::{Path, Query, State}; use axum::response::IntoResponse; use axum::routing::{get, post}; -use futures::{Future, FutureExt, TryStreamExt}; +use futures::future::BoxFuture; +use futures::{FutureExt, TryStreamExt}; use itertools::Itertools; use serde::{Deserialize, Serialize}; use std::net::SocketAddr; -use std::pin::Pin; use std::str::FromStr; use std::time::Duration; use tracing::{debug, info}; @@ -46,10 +46,7 @@ impl HttpApi { /// Run the HTTP server forever on the given address. /// If read_only is passed, no state-modifying methods will be exposed. #[inline(never)] - pub fn make_http_api_and_run( - self, - addr: SocketAddr, - ) -> Pin> + Send>> { + pub fn make_http_api_and_run(self, addr: SocketAddr) -> BoxFuture<'static, anyhow::Result<()>> { let state = self.inner; async fn api_root() -> impl IntoResponse { diff --git a/crates/librqbit/src/http_api_client.rs b/crates/librqbit/src/http_api_client.rs index a1bfb47..4414afa 100644 --- a/crates/librqbit/src/http_api_client.rs +++ b/crates/librqbit/src/http_api_client.rs @@ -1,7 +1,5 @@ -use std::pin::Pin; - use anyhow::Context; -use futures::{Future, FutureExt}; +use futures::{future::BoxFuture, FutureExt}; use serde::Deserialize; use crate::{ @@ -75,7 +73,7 @@ impl HttpApiClient { } #[inline(never)] - pub fn validate_rqbit_server(&self) -> Pin> + '_>> { + pub fn validate_rqbit_server(&self) -> BoxFuture<'_, anyhow::Result<()>> { async move { let response = self.client.get(self.base_url.clone()).send().await?; let root: ApiRoot = json_response(response).await?; @@ -91,7 +89,7 @@ impl HttpApiClient { &'a self, torrent: AddTorrent<'a>, opts: Option, - ) -> Pin> + 'a>> { + ) -> BoxFuture<'a, anyhow::Result> { async move { let opts = opts.unwrap_or_default(); let params = TorrentAddQueryParams { diff --git a/crates/librqbit/src/session.rs b/crates/librqbit/src/session.rs index 9ee814d..f781d49 100644 --- a/crates/librqbit/src/session.rs +++ b/crates/librqbit/src/session.rs @@ -4,7 +4,6 @@ use std::{ io::{BufReader, BufWriter, Read}, net::SocketAddr, path::PathBuf, - pin::Pin, str::FromStr, sync::Arc, time::Duration, @@ -25,7 +24,7 @@ use bencode::{bencode_serialize_to_writer, BencodeDeserializer}; use buffers::{ByteBuf, ByteBufT, ByteString}; use clone_to_owned::CloneToOwned; use dht::{Dht, DhtBuilder, DhtConfig, Id20, PersistentDht, PersistentDhtConfig}; -use futures::{stream::FuturesUnordered, Future, FutureExt, TryFutureExt}; +use futures::{future::BoxFuture, stream::FuturesUnordered, FutureExt, TryFutureExt}; use librqbit_core::{ directories::get_configuration_directory, magnet::Magnet, @@ -381,7 +380,7 @@ pub(crate) struct CheckedIncomingConnection { impl Session { /// Create a new session. The passed in folder will be used as a default unless overriden per torrent. #[inline(never)] - pub fn new(output_folder: PathBuf) -> Pin>>>> { + pub fn new(output_folder: PathBuf) -> BoxFuture<'static, anyhow::Result>> { Self::new_with_opts(output_folder, SessionOptions::default()) } @@ -399,7 +398,7 @@ impl Session { pub fn new_with_opts( output_folder: PathBuf, mut opts: SessionOptions, - ) -> Pin>>>> { + ) -> BoxFuture<'static, anyhow::Result>> { async move { let peer_id = opts.peer_id.unwrap_or_else(generate_peer_id); let token = CancellationToken::new(); @@ -751,7 +750,7 @@ impl Session { &'a self, add: AddTorrent<'a>, opts: Option, - ) -> Pin> + Send + 'a>> { + ) -> BoxFuture<'a, anyhow::Result> { async move { // Magnet links are different in that we first need to discover the metadata. let span = error_span!("add_torrent"); diff --git a/crates/librqbit/src/torrent_state/mod.rs b/crates/librqbit/src/torrent_state/mod.rs index 1e795de..a3fe61f 100644 --- a/crates/librqbit/src/torrent_state/mod.rs +++ b/crates/librqbit/src/torrent_state/mod.rs @@ -8,7 +8,6 @@ use std::collections::HashSet; use std::net::SocketAddr; use std::path::Path; use std::path::PathBuf; -use std::pin::Pin; use std::sync::atomic::Ordering; use std::sync::Arc; use std::time::Duration; @@ -16,7 +15,7 @@ use std::time::Duration; use anyhow::bail; use anyhow::Context; use buffers::ByteString; -use futures::Future; +use futures::future::BoxFuture; use futures::FutureExt; use librqbit_core::hash_id::Id20; use librqbit_core::lengths::Lengths; @@ -399,7 +398,7 @@ impl ManagedTorrent { } #[inline(never)] - pub fn wait_until_completed(&self) -> Pin> + '_>> { + pub fn wait_until_completed(&self) -> BoxFuture<'_, anyhow::Result<()>> { async move { // TODO: rewrite, this polling is horrible let live = loop {