Tiny refactor for stream types

This commit is contained in:
Igor Katson 2024-03-02 11:18:38 +00:00
parent 466cad06e0
commit 5d6ecb8065
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
2 changed files with 13 additions and 9 deletions

View file

@ -24,7 +24,11 @@ use bencode::{bencode_serialize_to_writer, BencodeDeserializer};
use buffers::{ByteBuf, ByteBufT, ByteString}; use buffers::{ByteBuf, ByteBufT, ByteString};
use clone_to_owned::CloneToOwned; use clone_to_owned::CloneToOwned;
use dht::{Dht, DhtBuilder, DhtConfig, Id20, PersistentDht, PersistentDhtConfig}; use dht::{Dht, DhtBuilder, DhtConfig, Id20, PersistentDht, PersistentDhtConfig};
use futures::{future::BoxFuture, stream::FuturesUnordered, FutureExt, Stream, TryFutureExt}; use futures::{
future::BoxFuture,
stream::{BoxStream, FuturesUnordered},
FutureExt, Stream, TryFutureExt,
};
use itertools::Itertools; use itertools::Itertools;
use librqbit_core::{ use librqbit_core::{
directories::get_configuration_directory, directories::get_configuration_directory,
@ -247,13 +251,13 @@ fn compute_only_files(
} }
fn merge_two_optional_streams<T>( fn merge_two_optional_streams<T>(
s1: Option<impl Stream<Item = T> + Send + Unpin + 'static>, s1: Option<impl Stream<Item = T> + Send + 'static>,
s2: Option<impl Stream<Item = T> + Send + Unpin + 'static>, s2: Option<impl Stream<Item = T> + Send + 'static>,
) -> Option<Box<dyn Stream<Item = T> + Send + Unpin + 'static>> { ) -> Option<BoxStream<'static, T>> {
match (s1, s2) { match (s1, s2) {
(Some(s1), None) => Some(Box::new(s1)), (Some(s1), None) => Some(Box::pin(s1)),
(None, Some(s2)) => Some(Box::new(s2)), (None, Some(s2)) => Some(Box::pin(s2)),
(Some(s1), Some(s2)) => Some(Box::new(s1.chain(s2))), (Some(s1), Some(s2)) => Some(Box::pin(s1.chain(s2))),
(None, None) => None, (None, None) => None,
} }
} }

View file

@ -1,8 +1,8 @@
use std::net::SocketAddr; use std::net::SocketAddr;
use futures::Stream; use futures::stream::BoxStream;
pub type BF = bitvec::vec::BitVec<u8, bitvec::order::Msb0>; pub type BF = bitvec::vec::BitVec<u8, bitvec::order::Msb0>;
pub type PeerHandle = SocketAddr; pub type PeerHandle = SocketAddr;
pub type PeerStream = Box<dyn Stream<Item = SocketAddr> + Unpin + Send + 'static>; pub type PeerStream = BoxStream<'static, SocketAddr>;