Shorten Pin<Box to BoxFuture
This commit is contained in:
parent
1b79b66cc3
commit
a001bb8c97
6 changed files with 19 additions and 27 deletions
|
|
@ -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<Box<dyn Future<Output = anyhow::Result<()>> + 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 {
|
||||
|
|
|
|||
|
|
@ -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<Box<dyn Future<Output = anyhow::Result<()>> + '_>> {
|
||||
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<AddTorrentOptions>,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<ApiAddTorrentResponse>> + 'a>> {
|
||||
) -> BoxFuture<'a, anyhow::Result<ApiAddTorrentResponse>> {
|
||||
async move {
|
||||
let opts = opts.unwrap_or_default();
|
||||
let params = TorrentAddQueryParams {
|
||||
|
|
|
|||
|
|
@ -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<Box<dyn Future<Output = anyhow::Result<Arc<Self>>>>> {
|
||||
pub fn new(output_folder: PathBuf) -> BoxFuture<'static, anyhow::Result<Arc<Self>>> {
|
||||
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<Box<dyn Future<Output = anyhow::Result<Arc<Self>>>>> {
|
||||
) -> BoxFuture<'static, anyhow::Result<Arc<Self>>> {
|
||||
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<AddTorrentOptions>,
|
||||
) -> Pin<Box<dyn Future<Output = anyhow::Result<AddTorrentResponse>> + Send + 'a>> {
|
||||
) -> BoxFuture<'a, anyhow::Result<AddTorrentResponse>> {
|
||||
async move {
|
||||
// Magnet links are different in that we first need to discover the metadata.
|
||||
let span = error_span!("add_torrent");
|
||||
|
|
|
|||
|
|
@ -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<Box<dyn Future<Output = anyhow::Result<()>> + '_>> {
|
||||
pub fn wait_until_completed(&self) -> BoxFuture<'_, anyhow::Result<()>> {
|
||||
async move {
|
||||
// TODO: rewrite, this polling is horrible
|
||||
let live = loop {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue