Struct libp2p_swarm::Swarm
source · pub struct Swarm<TBehaviour>where
TBehaviour: NetworkBehaviour,{ /* private fields */ }
Expand description
Contains the state of the network, plus the way it should behave.
Note: Needs to be polled via <Swarm as Stream>
in order to make
progress.
Implementations§
source§impl<TBehaviour> Swarm<TBehaviour>where
TBehaviour: NetworkBehaviour,
impl<TBehaviour> Swarm<TBehaviour>where TBehaviour: NetworkBehaviour,
sourcepub fn with_executor(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId,
executor: impl Executor + Send + 'static
) -> Self
👎Deprecated: Use SwarmBuilder::with_executor
instead.
pub fn with_executor( transport: Boxed<(PeerId, StreamMuxerBox)>, behaviour: TBehaviour, local_peer_id: PeerId, executor: impl Executor + Send + 'static ) -> Self
SwarmBuilder::with_executor
instead.Builds a new Swarm
with a provided executor.
sourcepub fn with_tokio_executor(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId
) -> Self
👎Deprecated: Use SwarmBuilder::with_tokio_executor
instead.Available on crate feature tokio
and neither Emscripten nor WASI nor target_os="unknown"
only.
pub fn with_tokio_executor( transport: Boxed<(PeerId, StreamMuxerBox)>, behaviour: TBehaviour, local_peer_id: PeerId ) -> Self
SwarmBuilder::with_tokio_executor
instead.tokio
and neither Emscripten nor WASI nor target_os="unknown"
only.Builds a new Swarm
with a tokio executor.
sourcepub fn with_async_std_executor(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId
) -> Self
👎Deprecated: Use SwarmBuilder::with_async_std_executor
instead.Available on crate feature async-std
and neither Emscripten nor WASI nor target_os="unknown"
only.
pub fn with_async_std_executor( transport: Boxed<(PeerId, StreamMuxerBox)>, behaviour: TBehaviour, local_peer_id: PeerId ) -> Self
SwarmBuilder::with_async_std_executor
instead.async-std
and neither Emscripten nor WASI nor target_os="unknown"
only.Builds a new Swarm
with an async-std executor.
sourcepub fn with_threadpool_executor(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId
) -> Self
👎Deprecated: The futures::executor::ThreadPool
executor is deprecated. See https://github.com/libp2p/rust-libp2p/issues/3107.
pub fn with_threadpool_executor( transport: Boxed<(PeerId, StreamMuxerBox)>, behaviour: TBehaviour, local_peer_id: PeerId ) -> Self
futures::executor::ThreadPool
executor is deprecated. See https://github.com/libp2p/rust-libp2p/issues/3107.Builds a new Swarm
with a threadpool executor.
sourcepub fn with_wasm_executor(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId
) -> Self
👎Deprecated: Use SwarmBuilder::with_wasm_executor
instead.Available on crate feature wasm-bindgen
only.
pub fn with_wasm_executor( transport: Boxed<(PeerId, StreamMuxerBox)>, behaviour: TBehaviour, local_peer_id: PeerId ) -> Self
SwarmBuilder::with_wasm_executor
instead.wasm-bindgen
only.Builds a new Swarm
with a wasm executor.
Background tasks will be executed by the browser on the next micro-tick.
Spawning a task is similar too:
function spawn(task: () => Promise<void>) {
task()
}
sourcepub fn without_executor(
transport: Boxed<(PeerId, StreamMuxerBox)>,
behaviour: TBehaviour,
local_peer_id: PeerId
) -> Self
👎Deprecated: Use SwarmBuilder::without_executor
instead.
pub fn without_executor( transport: Boxed<(PeerId, StreamMuxerBox)>, behaviour: TBehaviour, local_peer_id: PeerId ) -> Self
SwarmBuilder::without_executor
instead.Builds a new Swarm
without an executor, instead using the current task.
⚠️ Performance warning
All connections will be polled on the current task, thus quite bad performance
characteristics should be expected. Whenever possible use an executor and
Swarm::with_executor
.
sourcepub fn network_info(&self) -> NetworkInfo
pub fn network_info(&self) -> NetworkInfo
Returns information about the connections underlying the Swarm
.
sourcepub fn listen_on(
&mut self,
addr: Multiaddr
) -> Result<ListenerId, TransportError<Error>>
pub fn listen_on( &mut self, addr: Multiaddr ) -> Result<ListenerId, TransportError<Error>>
Starts listening on the given address. Returns an error if the address is not supported.
Listeners report their new listening addresses as SwarmEvent::NewListenAddr
.
Depending on the underlying transport, one listener may have multiple listening addresses.
sourcepub fn remove_listener(&mut self, listener_id: ListenerId) -> bool
pub fn remove_listener(&mut self, listener_id: ListenerId) -> bool
Remove some listener.
Returns true
if there was a listener with this ID, false
otherwise.
sourcepub fn dial(&mut self, opts: impl Into<DialOpts>) -> Result<(), DialError>
pub fn dial(&mut self, opts: impl Into<DialOpts>) -> Result<(), DialError>
Dial a known or unknown peer.
See also DialOpts
.
let mut swarm = SwarmBuilder::without_executor(
DummyTransport::new().boxed(),
dummy::Behaviour,
PeerId::random(),
).build();
// Dial a known peer.
swarm.dial(PeerId::random());
// Dial an unknown peer.
swarm.dial("/ip6/::1/tcp/12345".parse::<Multiaddr>().unwrap());
sourcepub fn listeners(&self) -> impl Iterator<Item = &Multiaddr>
pub fn listeners(&self) -> impl Iterator<Item = &Multiaddr>
Returns an iterator that produces the list of addresses we’re listening on.
sourcepub fn local_peer_id(&self) -> &PeerId
pub fn local_peer_id(&self) -> &PeerId
Returns the peer ID of the swarm passed as parameter.
sourcepub fn external_addresses(&self) -> impl Iterator<Item = &AddressRecord>
pub fn external_addresses(&self) -> impl Iterator<Item = &AddressRecord>
Returns an iterator for AddressRecord
s of external addresses
of the local node, in decreasing order of their current
score.
sourcepub fn add_external_address(
&mut self,
a: Multiaddr,
s: AddressScore
) -> AddAddressResult
pub fn add_external_address( &mut self, a: Multiaddr, s: AddressScore ) -> AddAddressResult
Adds an external address record for the local node.
An external address is an address of the local node known to
be (likely) reachable for other nodes, possibly taking into
account NAT. The external addresses of the local node may be
shared with other nodes by the NetworkBehaviour
.
The associated score determines both the position of the address
in the list of external addresses (which can determine the
order in which addresses are used to connect to) as well as
how long the address is retained in the list, depending on
how frequently it is reported by the NetworkBehaviour
via
ToSwarm::ReportObservedAddr
or explicitly
through this method.
sourcepub fn remove_external_address(&mut self, addr: &Multiaddr) -> bool
pub fn remove_external_address(&mut self, addr: &Multiaddr) -> bool
Removes an external address of the local node, regardless of
its current score. See Swarm::add_external_address
for details.
Returns true
if the address existed and was removed, false
otherwise.
sourcepub fn ban_peer_id(&mut self, peer_id: PeerId)
👎Deprecated since 0.42.1: Use libp2p::allow_block_list
instead.
pub fn ban_peer_id(&mut self, peer_id: PeerId)
libp2p::allow_block_list
instead.Bans a peer by its peer ID.
Any incoming connection and any dialing attempt will immediately be rejected. This function has no effect if the peer is already banned.
sourcepub fn unban_peer_id(&mut self, peer_id: PeerId)
👎Deprecated since 0.42.1: Use libp2p::allow_block_list
instead.
pub fn unban_peer_id(&mut self, peer_id: PeerId)
libp2p::allow_block_list
instead.Unbans a peer.
sourcepub fn disconnect_peer_id(&mut self, peer_id: PeerId) -> Result<(), ()>
pub fn disconnect_peer_id(&mut self, peer_id: PeerId) -> Result<(), ()>
Disconnects a peer by its peer ID, closing all connections to said peer.
Returns Ok(())
if there was one or more established connections to the peer.
Note: Closing a connection via Swarm::disconnect_peer_id
does
not inform the corresponding ConnectionHandler
.
Closing a connection via a ConnectionHandler
can be done either in a
collaborative manner across ConnectionHandler
s
with ConnectionHandler::connection_keep_alive
or directly with
ConnectionHandlerEvent::Close
.
sourcepub fn is_connected(&self, peer_id: &PeerId) -> bool
pub fn is_connected(&self, peer_id: &PeerId) -> bool
Checks whether there is an established connection to a peer.
sourcepub fn connected_peers(&self) -> impl Iterator<Item = &PeerId>
pub fn connected_peers(&self) -> impl Iterator<Item = &PeerId>
Returns the currently connected peers.
sourcepub fn behaviour(&self) -> &TBehaviour
pub fn behaviour(&self) -> &TBehaviour
Returns a reference to the provided NetworkBehaviour
.
sourcepub fn behaviour_mut(&mut self) -> &mut TBehaviour
pub fn behaviour_mut(&mut self) -> &mut TBehaviour
Returns a mutable reference to the provided NetworkBehaviour
.
Trait Implementations§
source§impl<TBehaviour> FusedStream for Swarm<TBehaviour>where
TBehaviour: NetworkBehaviour,
impl<TBehaviour> FusedStream for Swarm<TBehaviour>where TBehaviour: NetworkBehaviour,
The stream of swarm events never terminates, so we can implement fused for it.
source§fn is_terminated(&self) -> bool
fn is_terminated(&self) -> bool
true
if the stream should no longer be polled.source§impl<TBehaviour> Stream for Swarm<TBehaviour>where
TBehaviour: NetworkBehaviour,
impl<TBehaviour> Stream for Swarm<TBehaviour>where TBehaviour: NetworkBehaviour,
Stream of events returned by Swarm
.
Includes events from the NetworkBehaviour
as well as events about
connection and listener status. See SwarmEvent
for details.
Note: This stream is infinite and it is guaranteed that
[Stream::poll_next
] will never return Poll::Ready(None)
.
§type Item = SwarmEvent<<TBehaviour as NetworkBehaviour>::OutEvent, <<<TBehaviour as NetworkBehaviour>::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error>
type Item = SwarmEvent<<TBehaviour as NetworkBehaviour>::OutEvent, <<<TBehaviour as NetworkBehaviour>::ConnectionHandler as IntoConnectionHandler>::Handler as ConnectionHandler>::Error>
impl<TBehaviour> Unpin for Swarm<TBehaviour>where TBehaviour: NetworkBehaviour,
Auto Trait Implementations§
impl<TBehaviour> !RefUnwindSafe for Swarm<TBehaviour>
impl<TBehaviour> Send for Swarm<TBehaviour>where TBehaviour: Send,
impl<TBehaviour> !Sync for Swarm<TBehaviour>
impl<TBehaviour> !UnwindSafe for Swarm<TBehaviour>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> StreamExt for Twhere
T: Stream + ?Sized,
impl<T> StreamExt for Twhere T: Stream + ?Sized,
§fn next(&mut self) -> Next<'_, Self> ⓘwhere
Self: Unpin,
fn next(&mut self) -> Next<'_, Self> ⓘwhere Self: Unpin,
§fn into_future(self) -> StreamFuture<Self> ⓘwhere
Self: Sized + Unpin,
fn into_future(self) -> StreamFuture<Self> ⓘwhere Self: Sized + Unpin,
§fn map<T, F>(self, f: F) -> Map<Self, F>where
F: FnMut(Self::Item) -> T,
Self: Sized,
fn map<T, F>(self, f: F) -> Map<Self, F>where F: FnMut(Self::Item) -> T, Self: Sized,
§fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where Self: Sized,
§fn filter<Fut, F>(self, f: F) -> Filter<Self, Fut, F>where
F: FnMut(&Self::Item) -> Fut,
Fut: Future<Output = bool>,
Self: Sized,
fn filter<Fut, F>(self, f: F) -> Filter<Self, Fut, F>where F: FnMut(&Self::Item) -> Fut, Fut: Future<Output = bool>, Self: Sized,
§fn filter_map<Fut, T, F>(self, f: F) -> FilterMap<Self, Fut, F>where
F: FnMut(Self::Item) -> Fut,
Fut: Future<Output = Option<T>>,
Self: Sized,
fn filter_map<Fut, T, F>(self, f: F) -> FilterMap<Self, Fut, F>where F: FnMut(Self::Item) -> Fut, Fut: Future<Output = Option<T>>, Self: Sized,
§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>where
F: FnMut(Self::Item) -> Fut,
Fut: Future,
Self: Sized,
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>where F: FnMut(Self::Item) -> Fut, Fut: Future, Self: Sized,
§fn collect<C>(self) -> Collect<Self, C> ⓘwhere
C: Default + Extend<Self::Item>,
Self: Sized,
fn collect<C>(self) -> Collect<Self, C> ⓘwhere C: Default + Extend<Self::Item>, Self: Sized,
§fn unzip<A, B, FromA, FromB>(self) -> Unzip<Self, FromA, FromB> ⓘwhere
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
Self: Sized + Stream<Item = (A, B)>,
fn unzip<A, B, FromA, FromB>(self) -> Unzip<Self, FromA, FromB> ⓘwhere FromA: Default + Extend<A>, FromB: Default + Extend<B>, Self: Sized + Stream<Item = (A, B)>,
§fn concat(self) -> Concat<Self> ⓘwhere
Self: Sized,
Self::Item: Extend<<Self::Item as IntoIterator>::Item> + IntoIterator + Default,
fn concat(self) -> Concat<Self> ⓘwhere Self: Sized, Self::Item: Extend<<Self::Item as IntoIterator>::Item> + IntoIterator + Default,
§fn count(self) -> Count<Self> ⓘwhere
Self: Sized,
fn count(self) -> Count<Self> ⓘwhere Self: Sized,
§fn fold<T, Fut, F>(self, init: T, f: F) -> Fold<Self, Fut, T, F> ⓘwhere
F: FnMut(T, Self::Item) -> Fut,
Fut: Future<Output = T>,
Self: Sized,
fn fold<T, Fut, F>(self, init: T, f: F) -> Fold<Self, Fut, T, F> ⓘwhere F: FnMut(T, Self::Item) -> Fut, Fut: Future<Output = T>, Self: Sized,
§fn any<Fut, F>(self, f: F) -> Any<Self, Fut, F> ⓘwhere
F: FnMut(Self::Item) -> Fut,
Fut: Future<Output = bool>,
Self: Sized,
fn any<Fut, F>(self, f: F) -> Any<Self, Fut, F> ⓘwhere F: FnMut(Self::Item) -> Fut, Fut: Future<Output = bool>, Self: Sized,
true
if any element in stream satisfied a predicate. Read more§fn all<Fut, F>(self, f: F) -> All<Self, Fut, F> ⓘwhere
F: FnMut(Self::Item) -> Fut,
Fut: Future<Output = bool>,
Self: Sized,
fn all<Fut, F>(self, f: F) -> All<Self, Fut, F> ⓘwhere F: FnMut(Self::Item) -> Fut, Fut: Future<Output = bool>, Self: Sized,
true
if all element in stream satisfied a predicate. Read more§fn flatten(self) -> Flatten<Self>where
Self::Item: Stream,
Self: Sized,
fn flatten(self) -> Flatten<Self>where Self::Item: Stream, Self: Sized,
§fn flatten_unordered(
self,
limit: impl Into<Option<usize>>
) -> FlattenUnorderedWithFlowController<Self, ()>where
Self::Item: Stream + Unpin,
Self: Sized,
fn flatten_unordered( self, limit: impl Into<Option<usize>> ) -> FlattenUnorderedWithFlowController<Self, ()>where Self::Item: Stream + Unpin, Self: Sized,
futures_no_atomic_cas
and crate feature alloc
only.§fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where
F: FnMut(Self::Item) -> U,
U: Stream,
Self: Sized,
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where F: FnMut(Self::Item) -> U, U: Stream, Self: Sized,
§fn flat_map_unordered<U, F>(
self,
limit: impl Into<Option<usize>>,
f: F
) -> FlatMapUnordered<Self, U, F>where
U: Stream + Unpin,
F: FnMut(Self::Item) -> U,
Self: Sized,
fn flat_map_unordered<U, F>( self, limit: impl Into<Option<usize>>, f: F ) -> FlatMapUnordered<Self, U, F>where U: Stream + Unpin, F: FnMut(Self::Item) -> U, Self: Sized,
futures_no_atomic_cas
and crate feature alloc
only.StreamExt::map
] but flattens nested Stream
s
and polls them concurrently, yielding items in any order, as they made
available. Read more§fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>where
F: FnMut(&mut S, Self::Item) -> Fut,
Fut: Future<Output = Option<B>>,
Self: Sized,
fn scan<S, B, Fut, F>(self, initial_state: S, f: F) -> Scan<Self, S, Fut, F>where F: FnMut(&mut S, Self::Item) -> Fut, Fut: Future<Output = Option<B>>, Self: Sized,
StreamExt::fold
] that holds internal state
and produces a new stream. Read more§fn skip_while<Fut, F>(self, f: F) -> SkipWhile<Self, Fut, F>where
F: FnMut(&Self::Item) -> Fut,
Fut: Future<Output = bool>,
Self: Sized,
fn skip_while<Fut, F>(self, f: F) -> SkipWhile<Self, Fut, F>where F: FnMut(&Self::Item) -> Fut, Fut: Future<Output = bool>, Self: Sized,
true
. Read more§fn take_while<Fut, F>(self, f: F) -> TakeWhile<Self, Fut, F>where
F: FnMut(&Self::Item) -> Fut,
Fut: Future<Output = bool>,
Self: Sized,
fn take_while<Fut, F>(self, f: F) -> TakeWhile<Self, Fut, F>where F: FnMut(&Self::Item) -> Fut, Fut: Future<Output = bool>, Self: Sized,
true
. Read more§fn take_until<Fut>(self, fut: Fut) -> TakeUntil<Self, Fut>where
Fut: Future,
Self: Sized,
fn take_until<Fut>(self, fut: Fut) -> TakeUntil<Self, Fut>where Fut: Future, Self: Sized,
§fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F> ⓘwhere
F: FnMut(Self::Item) -> Fut,
Fut: Future<Output = ()>,
Self: Sized,
fn for_each<Fut, F>(self, f: F) -> ForEach<Self, Fut, F> ⓘwhere F: FnMut(Self::Item) -> Fut, Fut: Future<Output = ()>, Self: Sized,
§fn for_each_concurrent<Fut, F>(
self,
limit: impl Into<Option<usize>>,
f: F
) -> ForEachConcurrent<Self, Fut, F> ⓘwhere
F: FnMut(Self::Item) -> Fut,
Fut: Future<Output = ()>,
Self: Sized,
fn for_each_concurrent<Fut, F>( self, limit: impl Into<Option<usize>>, f: F ) -> ForEachConcurrent<Self, Fut, F> ⓘwhere F: FnMut(Self::Item) -> Fut, Fut: Future<Output = ()>, Self: Sized,
futures_no_atomic_cas
and crate feature alloc
only.§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where Self: Sized,
n
items of the underlying stream. Read more§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where Self: Sized,
n
items of the underlying stream. Read more§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where Self: Sized + UnwindSafe,
std
only.§fn boxed<'a>(
self
) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a, Global>>where
Self: Sized + Send + 'a,
fn boxed<'a>( self ) -> Pin<Box<dyn Stream<Item = Self::Item> + Send + 'a, Global>>where Self: Sized + Send + 'a,
alloc
only.§fn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a, Global>>where
Self: Sized + 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'a, Global>>where Self: Sized + 'a,
alloc
only.§fn buffered(self, n: usize) -> Buffered<Self>where
Self::Item: Future,
Self: Sized,
fn buffered(self, n: usize) -> Buffered<Self>where Self::Item: Future, Self: Sized,
futures_no_atomic_cas
and crate feature alloc
only.§fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>where
Self::Item: Future,
Self: Sized,
fn buffer_unordered(self, n: usize) -> BufferUnordered<Self>where Self::Item: Future, Self: Sized,
futures_no_atomic_cas
and crate feature alloc
only.§fn zip<St>(self, other: St) -> Zip<Self, St>where
St: Stream,
Self: Sized,
fn zip<St>(self, other: St) -> Zip<Self, St>where St: Stream, Self: Sized,
§fn chain<St>(self, other: St) -> Chain<Self, St>where
St: Stream<Item = Self::Item>,
Self: Sized,
fn chain<St>(self, other: St) -> Chain<Self, St>where St: Stream<Item = Self::Item>, Self: Sized,
§fn peekable(self) -> Peekable<Self>where
Self: Sized,
fn peekable(self) -> Peekable<Self>where Self: Sized,
peek
method. Read more§fn chunks(self, capacity: usize) -> Chunks<Self>where
Self: Sized,
fn chunks(self, capacity: usize) -> Chunks<Self>where Self: Sized,
alloc
only.§fn ready_chunks(self, capacity: usize) -> ReadyChunks<Self>where
Self: Sized,
fn ready_chunks(self, capacity: usize) -> ReadyChunks<Self>where Self: Sized,
alloc
only.§fn forward<S>(self, sink: S) -> Forward<Self, S> ⓘwhere
S: Sink<Self::Ok, Error = Self::Error>,
Self: TryStream + Sized,
fn forward<S>(self, sink: S) -> Forward<Self, S> ⓘwhere S: Sink<Self::Ok, Error = Self::Error>, Self: TryStream + Sized,
sink
only.§fn split<Item>(self) -> (SplitSink<Self, Item>, SplitStream<Self>)where
Self: Sink<Item> + Sized,
fn split<Item>(self) -> (SplitSink<Self, Item>, SplitStream<Self>)where Self: Sink<Item> + Sized,
sink
only.§fn inspect<F>(self, f: F) -> Inspect<Self, F>where
F: FnMut(&Self::Item),
Self: Sized,
fn inspect<F>(self, f: F) -> Inspect<Self, F>where F: FnMut(&Self::Item), Self: Sized,
§fn left_stream<B>(self) -> Either<Self, B> ⓘwhere
B: Stream<Item = Self::Item>,
Self: Sized,
fn left_stream<B>(self) -> Either<Self, B> ⓘwhere B: Stream<Item = Self::Item>, Self: Sized,
§fn right_stream<B>(self) -> Either<B, Self> ⓘwhere
B: Stream<Item = Self::Item>,
Self: Sized,
fn right_stream<B>(self) -> Either<B, Self> ⓘwhere B: Stream<Item = Self::Item>, Self: Sized,
source§impl<T> StreamExt for Twhere
T: Stream + ?Sized,
impl<T> StreamExt for Twhere T: Stream + ?Sized,
source§fn next(&mut self) -> NextFuture<'_, Self>where
Self: Unpin,
fn next(&mut self) -> NextFuture<'_, Self>where Self: Unpin,
source§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where Self: Sized,
n
elements. Read moresource§fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>where Self: Sized, P: FnMut(&Self::Item) -> bool,
source§fn step_by(self, step: usize) -> StepBy<Self>where
Self: Sized,
fn step_by(self, step: usize) -> StepBy<Self>where Self: Sized,
step
th element. Read moresource§fn chain<U>(self, other: U) -> Chain<Self, U>where
Self: Sized,
U: Stream<Item = Self::Item>,
fn chain<U>(self, other: U) -> Chain<Self, U>where Self: Sized, U: Stream<Item = Self::Item>,
source§fn cloned<'a, T>(self) -> Cloned<Self>where
Self: Sized + Stream<Item = &'a T>,
T: Clone + 'a,
fn cloned<'a, T>(self) -> Cloned<Self>where Self: Sized + Stream<Item = &'a T>, T: Clone + 'a,
source§fn copied<'a, T>(self) -> Copied<Self>where
Self: Sized + Stream<Item = &'a T>,
T: Copy + 'a,
fn copied<'a, T>(self) -> Copied<Self>where Self: Sized + Stream<Item = &'a T>, T: Copy + 'a,
source§fn cycle(self) -> Cycle<Self>where
Self: Clone + Sized,
fn cycle(self) -> Cycle<Self>where Self: Clone + Sized,
source§fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where Self: Sized,
source§fn map<B, F>(self, f: F) -> Map<Self, F>where
Self: Sized,
F: FnMut(Self::Item) -> B,
fn map<B, F>(self, f: F) -> Map<Self, F>where Self: Sized, F: FnMut(Self::Item) -> B,
source§fn inspect<F>(self, f: F) -> Inspect<Self, F>where
Self: Sized,
F: FnMut(&Self::Item),
fn inspect<F>(self, f: F) -> Inspect<Self, F>where Self: Sized, F: FnMut(&Self::Item),
source§fn last(self) -> LastFuture<Self, Self::Item>where
Self: Sized,
fn last(self) -> LastFuture<Self, Self::Item>where Self: Sized,
source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where Self: Sized,
None
. Read moresource§fn filter<P>(self, predicate: P) -> Filter<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn filter<P>(self, predicate: P) -> Filter<Self, P>where Self: Sized, P: FnMut(&Self::Item) -> bool,
source§fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>where
Self: Sized,
F: FnMut(Self::Item) -> Option<B>,
fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>where Self: Sized, F: FnMut(Self::Item) -> Option<B>,
source§fn min_by_key<B, F>(self, key_by: F) -> MinByKeyFuture<Self, Self::Item, F>where
Self: Sized,
B: Ord,
F: FnMut(&Self::Item) -> B,
fn min_by_key<B, F>(self, key_by: F) -> MinByKeyFuture<Self, Self::Item, F>where Self: Sized, B: Ord, F: FnMut(&Self::Item) -> B,
None
is returned. Read moresource§fn max_by_key<B, F>(self, key_by: F) -> MaxByKeyFuture<Self, Self::Item, F>where
Self: Sized,
B: Ord,
F: FnMut(&Self::Item) -> B,
fn max_by_key<B, F>(self, key_by: F) -> MaxByKeyFuture<Self, Self::Item, F>where Self: Sized, B: Ord, F: FnMut(&Self::Item) -> B,
None
is returned. Read moresource§fn min_by<F>(self, compare: F) -> MinByFuture<Self, F, Self::Item>where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
fn min_by<F>(self, compare: F) -> MinByFuture<Self, F, Self::Item>where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering,
None
is returned. Read moresource§fn max(self) -> MaxFuture<Self, Self::Item>where
Self: Sized,
Self::Item: Ord,
fn max(self) -> MaxFuture<Self, Self::Item>where Self: Sized, Self::Item: Ord,
None
is returned. Read moresource§fn min(self) -> MinFuture<Self, Self::Item>where
Self: Sized,
Self::Item: Ord,
fn min(self) -> MinFuture<Self, Self::Item>where Self: Sized, Self::Item: Ord,
None
is returned. Read moresource§fn max_by<F>(self, compare: F) -> MaxByFuture<Self, F, Self::Item>where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
fn max_by<F>(self, compare: F) -> MaxByFuture<Self, F, Self::Item>where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering,
None
is returned. Read moresource§fn nth(&mut self, n: usize) -> NthFuture<'_, Self>where
Self: Unpin + Sized,
fn nth(&mut self, n: usize) -> NthFuture<'_, Self>where Self: Unpin + Sized,
source§fn all<F>(&mut self, f: F) -> AllFuture<'_, Self, F, Self::Item>where
Self: Unpin + Sized,
F: FnMut(Self::Item) -> bool,
fn all<F>(&mut self, f: F) -> AllFuture<'_, Self, F, Self::Item>where Self: Unpin + Sized, F: FnMut(Self::Item) -> bool,
source§fn find<P>(&mut self, p: P) -> FindFuture<'_, Self, P>where
Self: Unpin + Sized,
P: FnMut(&Self::Item) -> bool,
fn find<P>(&mut self, p: P) -> FindFuture<'_, Self, P>where Self: Unpin + Sized, P: FnMut(&Self::Item) -> bool,
source§fn find_map<F, B>(&mut self, f: F) -> FindMapFuture<'_, Self, F>where
Self: Unpin + Sized,
F: FnMut(Self::Item) -> Option<B>,
fn find_map<F, B>(&mut self, f: F) -> FindMapFuture<'_, Self, F>where Self: Unpin + Sized, F: FnMut(Self::Item) -> Option<B>,
source§fn fold<B, F>(self, init: B, f: F) -> FoldFuture<Self, F, B>where
Self: Sized,
F: FnMut(B, Self::Item) -> B,
fn fold<B, F>(self, init: B, f: F) -> FoldFuture<Self, F, B>where Self: Sized, F: FnMut(B, Self::Item) -> B,
source§fn for_each<F>(self, f: F) -> ForEachFuture<Self, F>where
Self: Sized,
F: FnMut(Self::Item),
fn for_each<F>(self, f: F) -> ForEachFuture<Self, F>where Self: Sized, F: FnMut(Self::Item),
source§fn any<F>(&mut self, f: F) -> AnyFuture<'_, Self, F, Self::Item>where
Self: Unpin + Sized,
F: FnMut(Self::Item) -> bool,
fn any<F>(&mut self, f: F) -> AnyFuture<'_, Self, F, Self::Item>where Self: Unpin + Sized, F: FnMut(Self::Item) -> bool,
source§fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>where
Self: Sized,
F: FnMut(&mut St, Self::Item) -> Option<B>,
fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>where Self: Sized, F: FnMut(&mut St, Self::Item) -> Option<B>,
source§fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>where Self: Sized, P: FnMut(&Self::Item) -> bool,
skip
s elements based on a predicate. Read moresource§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where Self: Sized,
n
elements. Read moresource§fn try_fold<B, F, T, E>(
&mut self,
init: T,
f: F
) -> TryFoldFuture<'_, Self, F, T>where
Self: Unpin + Sized,
F: FnMut(B, Self::Item) -> Result<T, E>,
fn try_fold<B, F, T, E>( &mut self, init: T, f: F ) -> TryFoldFuture<'_, Self, F, T>where Self: Unpin + Sized, F: FnMut(B, Self::Item) -> Result<T, E>,
source§fn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F>where
Self: Unpin + Sized,
F: FnMut(Self::Item) -> Result<(), E>,
fn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F>where Self: Unpin + Sized, F: FnMut(Self::Item) -> Result<(), E>,
source§fn zip<U>(self, other: U) -> Zip<Self, U>where
Self: Sized,
U: Stream,
fn zip<U>(self, other: U) -> Zip<Self, U>where Self: Sized, U: Stream,
source§fn partial_cmp<S>(self, other: S) -> PartialCmpFuture<Self, S>where
Self: Sized + Stream,
S: Stream,
Self::Item: PartialOrd<<S as Stream>::Item>,
fn partial_cmp<S>(self, other: S) -> PartialCmpFuture<Self, S>where Self: Sized + Stream, S: Stream, Self::Item: PartialOrd<<S as Stream>::Item>,
Stream
with those
of another. Read moresource§fn position<P>(&mut self, predicate: P) -> PositionFuture<'_, Self, P>where
Self: Unpin + Sized,
P: FnMut(Self::Item) -> bool,
fn position<P>(&mut self, predicate: P) -> PositionFuture<'_, Self, P>where Self: Unpin + Sized, P: FnMut(Self::Item) -> bool,
source§fn cmp<S>(self, other: S) -> CmpFuture<Self, S>where
Self: Sized + Stream,
S: Stream,
Self::Item: Ord,
fn cmp<S>(self, other: S) -> CmpFuture<Self, S>where Self: Sized + Stream, S: Stream, Self::Item: Ord,
Stream
with those
of another using ‘Ord’. Read moresource§fn ne<S>(self, other: S) -> NeFuture<Self, S>where
Self: Sized,
S: Stream,
Self::Item: PartialEq<<S as Stream>::Item>,
fn ne<S>(self, other: S) -> NeFuture<Self, S>where Self: Sized, S: Stream, Self::Item: PartialEq<<S as Stream>::Item>,
Stream
are lexicographically
not equal to those of another. Read moresource§fn ge<S>(self, other: S) -> GeFuture<Self, S>where
Self: Sized + Stream,
S: Stream,
Self::Item: PartialOrd<<S as Stream>::Item>,
fn ge<S>(self, other: S) -> GeFuture<Self, S>where Self: Sized + Stream, S: Stream, Self::Item: PartialOrd<<S as Stream>::Item>,
Stream
are lexicographically
greater than or equal to those of another. Read moresource§fn eq<S>(self, other: S) -> EqFuture<Self, S>where
Self: Sized + Stream,
S: Stream,
Self::Item: PartialEq<<S as Stream>::Item>,
fn eq<S>(self, other: S) -> EqFuture<Self, S>where Self: Sized + Stream, S: Stream, Self::Item: PartialEq<<S as Stream>::Item>,
Stream
are lexicographically
equal to those of another. Read moresource§fn gt<S>(self, other: S) -> GtFuture<Self, S>where
Self: Sized + Stream,
S: Stream,
Self::Item: PartialOrd<<S as Stream>::Item>,
fn gt<S>(self, other: S) -> GtFuture<Self, S>where Self: Sized + Stream, S: Stream, Self::Item: PartialOrd<<S as Stream>::Item>,
Stream
are lexicographically
greater than those of another. Read more§impl<S> StreamExt for Swhere
S: Stream + ?Sized,
impl<S> StreamExt for Swhere S: Stream + ?Sized,
§fn next(&mut self) -> NextFuture<'_, Self> ⓘwhere
Self: Unpin,
fn next(&mut self) -> NextFuture<'_, Self> ⓘwhere Self: Unpin,
§fn try_next<T, E>(&mut self) -> TryNextFuture<'_, Self> ⓘwhere
Self: Stream<Item = Result<T, E>> + Unpin,
fn try_next<T, E>(&mut self) -> TryNextFuture<'_, Self> ⓘwhere Self: Stream<Item = Result<T, E>> + Unpin,
§fn count(self) -> CountFuture<Self> ⓘwhere
Self: Sized,
fn count(self) -> CountFuture<Self> ⓘwhere Self: Sized,
§fn map<T, F>(self, f: F) -> Map<Self, F>where
Self: Sized,
F: FnMut(Self::Item) -> T,
fn map<T, F>(self, f: F) -> Map<Self, F>where Self: Sized, F: FnMut(Self::Item) -> T,
§fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where
Self: Sized,
U: Stream,
F: FnMut(Self::Item) -> U,
fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>where Self: Sized, U: Stream, F: FnMut(Self::Item) -> U,
§fn flatten(self) -> Flatten<Self>where
Self: Sized,
Self::Item: Stream,
fn flatten(self) -> Flatten<Self>where Self: Sized, Self::Item: Stream,
§fn then<F, Fut>(self, f: F) -> Then<Self, F, Fut>where
Self: Sized,
F: FnMut(Self::Item) -> Fut,
Fut: Future,
fn then<F, Fut>(self, f: F) -> Then<Self, F, Fut>where Self: Sized, F: FnMut(Self::Item) -> Fut, Fut: Future,
§fn filter<P>(self, predicate: P) -> Filter<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn filter<P>(self, predicate: P) -> Filter<Self, P>where Self: Sized, P: FnMut(&Self::Item) -> bool,
§fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>where
Self: Sized,
F: FnMut(Self::Item) -> Option<T>,
fn filter_map<T, F>(self, f: F) -> FilterMap<Self, F>where Self: Sized, F: FnMut(Self::Item) -> Option<T>,
§fn take(self, n: usize) -> Take<Self>where
Self: Sized,
fn take(self, n: usize) -> Take<Self>where Self: Sized,
n
items of the stream. Read more§fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>where Self: Sized, P: FnMut(&Self::Item) -> bool,
§fn skip(self, n: usize) -> Skip<Self>where
Self: Sized,
fn skip(self, n: usize) -> Skip<Self>where Self: Sized,
n
items of the stream. Read more§fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>where
Self: Sized,
P: FnMut(&Self::Item) -> bool,
fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>where Self: Sized, P: FnMut(&Self::Item) -> bool,
§fn chain<U>(self, other: U) -> Chain<Self, U>where
Self: Sized,
U: Stream<Item = Self::Item>,
fn chain<U>(self, other: U) -> Chain<Self, U>where Self: Sized, U: Stream<Item = Self::Item>,
§fn cloned<'a, T>(self) -> Cloned<Self>where
Self: Stream<Item = &'a T> + Sized,
T: Clone + 'a,
fn cloned<'a, T>(self) -> Cloned<Self>where Self: Stream<Item = &'a T> + Sized, T: Clone + 'a,
§fn copied<'a, T>(self) -> Copied<Self>where
Self: Stream<Item = &'a T> + Sized,
T: Copy + 'a,
fn copied<'a, T>(self) -> Copied<Self>where Self: Stream<Item = &'a T> + Sized, T: Copy + 'a,
§fn collect<C>(self) -> CollectFuture<Self, C> ⓘwhere
Self: Sized,
C: Default + Extend<Self::Item>,
fn collect<C>(self) -> CollectFuture<Self, C> ⓘwhere Self: Sized, C: Default + Extend<Self::Item>,
§fn try_collect<T, E, C>(self) -> TryCollectFuture<Self, C> ⓘwhere
Self: Stream<Item = Result<T, E>> + Sized,
C: Default + Extend<T>,
fn try_collect<T, E, C>(self) -> TryCollectFuture<Self, C> ⓘwhere Self: Stream<Item = Result<T, E>> + Sized, C: Default + Extend<T>,
§fn partition<B, P>(self, predicate: P) -> PartitionFuture<Self, P, B> ⓘwhere
Self: Sized,
B: Default + Extend<Self::Item>,
P: FnMut(&Self::Item) -> bool,
fn partition<B, P>(self, predicate: P) -> PartitionFuture<Self, P, B> ⓘwhere Self: Sized, B: Default + Extend<Self::Item>, P: FnMut(&Self::Item) -> bool,
predicate
is true
and those for which it is
false
, and then collects them into two collections. Read more§fn fold<T, F>(self, init: T, f: F) -> FoldFuture<Self, F, T> ⓘwhere
Self: Sized,
F: FnMut(T, Self::Item) -> T,
fn fold<T, F>(self, init: T, f: F) -> FoldFuture<Self, F, T> ⓘwhere Self: Sized, F: FnMut(T, Self::Item) -> T,
§fn try_fold<T, E, F, B>(
&mut self,
init: B,
f: F
) -> TryFoldFuture<'_, Self, F, B> ⓘwhere
Self: Stream<Item = Result<T, E>> + Unpin + Sized,
F: FnMut(B, T) -> Result<B, E>,
fn try_fold<T, E, F, B>( &mut self, init: B, f: F ) -> TryFoldFuture<'_, Self, F, B> ⓘwhere Self: Stream<Item = Result<T, E>> + Unpin + Sized, F: FnMut(B, T) -> Result<B, E>,
§fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>where
Self: Sized,
F: FnMut(&mut St, Self::Item) -> Option<B>,
fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>where Self: Sized, F: FnMut(&mut St, Self::Item) -> Option<B>,
§fn cycle(self) -> Cycle<Self>where
Self: Clone + Sized,
fn cycle(self) -> Cycle<Self>where Self: Clone + Sized,
§fn enumerate(self) -> Enumerate<Self>where
Self: Sized,
fn enumerate(self) -> Enumerate<Self>where Self: Sized,
(index, item)
. Read more§fn inspect<F>(self, f: F) -> Inspect<Self, F>where
Self: Sized,
F: FnMut(&Self::Item),
fn inspect<F>(self, f: F) -> Inspect<Self, F>where Self: Sized, F: FnMut(&Self::Item),
§fn nth(&mut self, n: usize) -> NthFuture<'_, Self> ⓘwhere
Self: Unpin,
fn nth(&mut self, n: usize) -> NthFuture<'_, Self> ⓘwhere Self: Unpin,
n
th item of the stream. Read more§fn last(self) -> LastFuture<Self> ⓘwhere
Self: Sized,
fn last(self) -> LastFuture<Self> ⓘwhere Self: Sized,
§fn find<P>(&mut self, predicate: P) -> FindFuture<'_, Self, P> ⓘwhere
Self: Unpin,
P: FnMut(&Self::Item) -> bool,
fn find<P>(&mut self, predicate: P) -> FindFuture<'_, Self, P> ⓘwhere Self: Unpin, P: FnMut(&Self::Item) -> bool,
§fn find_map<F, B>(&mut self, f: F) -> FindMapFuture<'_, Self, F> ⓘwhere
Self: Unpin,
F: FnMut(Self::Item) -> Option<B>,
fn find_map<F, B>(&mut self, f: F) -> FindMapFuture<'_, Self, F> ⓘwhere Self: Unpin, F: FnMut(Self::Item) -> Option<B>,
§fn position<P>(&mut self, predicate: P) -> PositionFuture<'_, Self, P> ⓘwhere
Self: Unpin,
P: FnMut(Self::Item) -> bool,
fn position<P>(&mut self, predicate: P) -> PositionFuture<'_, Self, P> ⓘwhere Self: Unpin, P: FnMut(Self::Item) -> bool,
§fn all<P>(&mut self, predicate: P) -> AllFuture<'_, Self, P> ⓘwhere
Self: Unpin,
P: FnMut(Self::Item) -> bool,
fn all<P>(&mut self, predicate: P) -> AllFuture<'_, Self, P> ⓘwhere Self: Unpin, P: FnMut(Self::Item) -> bool,
§fn any<P>(&mut self, predicate: P) -> AnyFuture<'_, Self, P> ⓘwhere
Self: Unpin,
P: FnMut(Self::Item) -> bool,
fn any<P>(&mut self, predicate: P) -> AnyFuture<'_, Self, P> ⓘwhere Self: Unpin, P: FnMut(Self::Item) -> bool,
§fn for_each<F>(self, f: F) -> ForEachFuture<Self, F> ⓘwhere
Self: Sized,
F: FnMut(Self::Item),
fn for_each<F>(self, f: F) -> ForEachFuture<Self, F> ⓘwhere Self: Sized, F: FnMut(Self::Item),
§fn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F> ⓘwhere
Self: Unpin,
F: FnMut(Self::Item) -> Result<(), E>,
fn try_for_each<F, E>(&mut self, f: F) -> TryForEachFuture<'_, Self, F> ⓘwhere Self: Unpin, F: FnMut(Self::Item) -> Result<(), E>,
§fn zip<U>(self, other: U) -> Zip<Self, U>where
Self: Sized,
U: Stream,
fn zip<U>(self, other: U) -> Zip<Self, U>where Self: Sized, U: Stream,
§fn unzip<A, B, FromA, FromB>(self) -> UnzipFuture<Self, FromA, FromB> ⓘwhere
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
Self: Stream<Item = (A, B)> + Sized,
fn unzip<A, B, FromA, FromB>(self) -> UnzipFuture<Self, FromA, FromB> ⓘwhere FromA: Default + Extend<A>, FromB: Default + Extend<B>, Self: Stream<Item = (A, B)> + Sized,
§fn race<S>(self, other: S) -> Race<Self, S>where
Self: Sized,
S: Stream<Item = Self::Item>,
fn race<S>(self, other: S) -> Race<Self, S>where Self: Sized, S: Stream<Item = Self::Item>,
std
only.other
stream, with no preference for either stream when both are ready. Read more