mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-07-03 19:51:33 +00:00
Address edition-2018 idioms. (#929)
This commit is contained in:
committed by
Pierre Krieger
parent
21810e46bd
commit
eeed66707b
@ -51,7 +51,7 @@ impl<TInEvent, TOutEvent, THandler, TReachErr, THandlerErr, TPeerId> fmt::Debug
|
||||
where
|
||||
TPeerId: fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
let mut list = f.debug_list();
|
||||
for (id, task) in &self.tasks {
|
||||
match *task {
|
||||
@ -127,7 +127,7 @@ where TOutEvent: fmt::Debug,
|
||||
THandlerErr: fmt::Debug,
|
||||
TPeerId: Eq + Hash + Clone + fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
match *self {
|
||||
CollectionEvent::NodeReached(ref inner) => {
|
||||
f.debug_tuple("CollectionEvent::NodeReached")
|
||||
@ -163,7 +163,7 @@ where TOutEvent: fmt::Debug,
|
||||
|
||||
/// Event that happens when we reach a node.
|
||||
#[must_use = "The node reached event is used to accept the newly-opened connection"]
|
||||
pub struct CollectionReachEvent<'a, TInEvent: 'a, TOutEvent: 'a, THandler: 'a, TReachErr, THandlerErr: 'a, TPeerId: 'a = PeerId> {
|
||||
pub struct CollectionReachEvent<'a, TInEvent, TOutEvent, THandler, TReachErr, THandlerErr, TPeerId = PeerId> {
|
||||
/// Peer id we connected to.
|
||||
peer_id: TPeerId,
|
||||
/// The task id that reached the node.
|
||||
@ -244,7 +244,7 @@ impl<'a, TInEvent, TOutEvent, THandler, TReachErr, THandlerErr, TPeerId> fmt::De
|
||||
where
|
||||
TPeerId: Eq + Hash + Clone + fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
f.debug_struct("CollectionReachEvent")
|
||||
.field("peer_id", &self.peer_id)
|
||||
.field("reach_attempt_id", &self.reach_attempt_id())
|
||||
@ -357,7 +357,7 @@ where
|
||||
///
|
||||
/// Returns `None` if we don't have a connection to this peer.
|
||||
#[inline]
|
||||
pub fn peer_mut(&mut self, id: &TPeerId) -> Option<PeerMut<TInEvent, TPeerId>> {
|
||||
pub fn peer_mut(&mut self, id: &TPeerId) -> Option<PeerMut<'_, TInEvent, TPeerId>> {
|
||||
let task = match self.nodes.get(id) {
|
||||
Some(&task) => task,
|
||||
None => return None,
|
||||
@ -394,7 +394,7 @@ where
|
||||
/// > **Note**: we use a regular `poll` method instead of implementing `Stream` in order to
|
||||
/// > remove the `Err` variant, but also because we want the `CollectionStream` to stay
|
||||
/// > borrowed if necessary.
|
||||
pub fn poll(&mut self) -> Async<CollectionEvent<TInEvent, TOutEvent, THandler, TReachErr, THandlerErr, TPeerId>> {
|
||||
pub fn poll(&mut self) -> Async<CollectionEvent<'_, TInEvent, TOutEvent, THandler, TReachErr, THandlerErr, TPeerId>> {
|
||||
let item = match self.inner.poll() {
|
||||
Async::Ready(item) => item,
|
||||
Async::NotReady => return Async::NotReady,
|
||||
@ -493,7 +493,7 @@ pub enum InterruptError {
|
||||
}
|
||||
|
||||
impl fmt::Display for InterruptError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
InterruptError::ReachAttemptNotFound =>
|
||||
write!(f, "The reach attempt could not be found."),
|
||||
@ -506,7 +506,7 @@ impl fmt::Display for InterruptError {
|
||||
impl error::Error for InterruptError {}
|
||||
|
||||
/// Access to a peer in the collection.
|
||||
pub struct PeerMut<'a, TInEvent: 'a, TPeerId: 'a = PeerId> {
|
||||
pub struct PeerMut<'a, TInEvent, TPeerId = PeerId> {
|
||||
inner: HandledNodesTask<'a, TInEvent>,
|
||||
tasks: &'a mut FnvHashMap<TaskId, TaskState<TPeerId>>,
|
||||
nodes: &'a mut FnvHashMap<TPeerId, TaskId>,
|
||||
|
@ -173,7 +173,7 @@ where
|
||||
TMuxer: StreamMuxer,
|
||||
THandler: NodeHandler<Substream = Substream<TMuxer>> + fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("HandledNode")
|
||||
.field("node", &self.node)
|
||||
.field("handler", &self.handler)
|
||||
@ -338,7 +338,7 @@ pub enum HandledNodeError<THandlerErr> {
|
||||
impl<THandlerErr> fmt::Display for HandledNodeError<THandlerErr>
|
||||
where THandlerErr: fmt::Display
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
HandledNodeError::Node(err) => write!(f, "{}", err),
|
||||
HandledNodeError::Handler(err) => write!(f, "{}", err),
|
||||
|
@ -68,7 +68,7 @@ pub struct HandledNodesTasks<TInEvent, TOutEvent, TIntoHandler, TReachErr, THand
|
||||
|
||||
/// List of node tasks to spawn.
|
||||
// TODO: stronger typing?
|
||||
to_spawn: SmallVec<[Box<Future<Item = (), Error = ()> + Send>; 8]>,
|
||||
to_spawn: SmallVec<[Box<dyn Future<Item = (), Error = ()> + Send>; 8]>,
|
||||
|
||||
/// Sender to emit events to the outside. Meant to be cloned and sent to tasks.
|
||||
events_tx: mpsc::UnboundedSender<(InToExtMessage<TOutEvent, TIntoHandler, TReachErr, THandlerErr, TPeerId>, TaskId)>,
|
||||
@ -79,7 +79,7 @@ pub struct HandledNodesTasks<TInEvent, TOutEvent, TIntoHandler, TReachErr, THand
|
||||
impl<TInEvent, TOutEvent, TIntoHandler, TReachErr, THandlerErr, TPeerId> fmt::Debug for
|
||||
HandledNodesTasks<TInEvent, TOutEvent, TIntoHandler, TReachErr, THandlerErr, TPeerId>
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
f.debug_list()
|
||||
.entries(self.tasks.keys().cloned())
|
||||
.finish()
|
||||
@ -100,7 +100,7 @@ where
|
||||
TReachErr: fmt::Display,
|
||||
THandlerErr: fmt::Display,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
TaskClosedEvent::Reach(err) => write!(f, "{}", err),
|
||||
TaskClosedEvent::Node(err) => write!(f, "{}", err),
|
||||
@ -253,7 +253,7 @@ impl<TInEvent, TOutEvent, TIntoHandler, TReachErr, THandlerErr, TPeerId>
|
||||
///
|
||||
/// Returns `None` if the task id is invalid.
|
||||
#[inline]
|
||||
pub fn task(&mut self, id: TaskId) -> Option<Task<TInEvent>> {
|
||||
pub fn task(&mut self, id: TaskId) -> Option<Task<'_, TInEvent>> {
|
||||
match self.tasks.entry(id) {
|
||||
Entry::Occupied(inner) => Some(Task { inner }),
|
||||
Entry::Vacant(_) => None,
|
||||
@ -316,7 +316,7 @@ impl<TInEvent, TOutEvent, TIntoHandler, TReachErr, THandlerErr, TPeerId>
|
||||
}
|
||||
|
||||
/// Access to a task in the collection.
|
||||
pub struct Task<'a, TInEvent: 'a> {
|
||||
pub struct Task<'a, TInEvent> {
|
||||
inner: OccupiedEntry<'a, TaskId, mpsc::UnboundedSender<TInEvent>>,
|
||||
}
|
||||
|
||||
@ -346,7 +346,7 @@ impl<'a, TInEvent> Task<'a, TInEvent> {
|
||||
}
|
||||
|
||||
impl<'a, TInEvent> fmt::Debug for Task<'a, TInEvent> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
f.debug_tuple("Task")
|
||||
.field(&self.id())
|
||||
.finish()
|
||||
|
@ -40,10 +40,6 @@ use void::Void;
|
||||
/// # Example
|
||||
///
|
||||
/// ```no_run
|
||||
/// # extern crate futures;
|
||||
/// # extern crate libp2p_core;
|
||||
/// # extern crate libp2p_tcp;
|
||||
/// # extern crate tokio;
|
||||
/// # fn main() {
|
||||
/// use futures::prelude::*;
|
||||
/// use libp2p_core::nodes::listeners::{ListenersEvent, ListenersStream};
|
||||
@ -238,7 +234,7 @@ impl<TTrans> fmt::Debug for ListenersStream<TTrans>
|
||||
where
|
||||
TTrans: Transport + fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
f.debug_struct("ListenersStream")
|
||||
.field("transport", &self.transport)
|
||||
.field("listeners", &self.listeners().collect::<Vec<_>>())
|
||||
@ -251,7 +247,7 @@ where
|
||||
TTrans: Transport,
|
||||
<TTrans::Listener as Stream>::Error: fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
match self {
|
||||
ListenersEvent::Incoming {
|
||||
ref listen_addr, ..
|
||||
@ -274,8 +270,6 @@ where
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
extern crate libp2p_tcp;
|
||||
|
||||
use super::*;
|
||||
use crate::transport;
|
||||
use assert_matches::assert_matches;
|
||||
|
@ -322,7 +322,7 @@ impl<TMuxer, TUserData> fmt::Debug for NodeStream<TMuxer, TUserData>
|
||||
where
|
||||
TMuxer: muxing::StreamMuxer,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
f.debug_struct("NodeStream")
|
||||
.field("inbound_state", &self.inbound_state)
|
||||
.field("outbound_state", &self.outbound_state)
|
||||
@ -351,7 +351,7 @@ where
|
||||
TMuxer::Substream: fmt::Debug,
|
||||
TUserData: fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
NodeEvent::InboundSubstream { substream } => {
|
||||
f.debug_struct("NodeEvent::OutboundClosed")
|
||||
|
@ -77,7 +77,7 @@ where
|
||||
TTrans: Transport + fmt::Debug,
|
||||
TPeerId: fmt::Debug + Eq + Hash,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
f.debug_struct("ReachAttempts")
|
||||
.field("listeners", &self.listeners)
|
||||
.field("active_nodes", &self.active_nodes)
|
||||
@ -108,7 +108,7 @@ impl<TPeerId> fmt::Debug for ReachAttempts<TPeerId>
|
||||
where
|
||||
TPeerId: fmt::Debug + Eq + Hash,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
f.debug_struct("ReachAttempts")
|
||||
.field("local_peer_id", &self.local_peer_id)
|
||||
.field("out_reach_attempts", &self.out_reach_attempts)
|
||||
@ -246,7 +246,7 @@ where
|
||||
THandlerErr: fmt::Debug,
|
||||
TPeerId: fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
match *self {
|
||||
RawSwarmEvent::ListenerClosed { ref listen_addr, ref result, .. } => {
|
||||
f.debug_struct("ListenerClosed")
|
||||
@ -337,7 +337,7 @@ where
|
||||
TTransErr: fmt::Display,
|
||||
TPeerId: fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
InternalReachErr::Transport(err) => write!(f, "{}", err),
|
||||
InternalReachErr::PeerIdMismatch { obtained } => {
|
||||
@ -397,7 +397,7 @@ where
|
||||
TTransErr: fmt::Display,
|
||||
TPeerId: fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
RawSwarmReachError::Transport(err) => write!(f, "{}", err),
|
||||
RawSwarmReachError::PeerIdMismatch { obtained } => {
|
||||
@ -432,7 +432,7 @@ pub enum UnknownPeerDialErr<TTransErr> {
|
||||
impl<TTransErr> fmt::Display for UnknownPeerDialErr<TTransErr>
|
||||
where TTransErr: fmt::Display
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
UnknownPeerDialErr::Transport(err) => write!(f, "{}", err),
|
||||
UnknownPeerDialErr::FoundLocalPeerId => {
|
||||
@ -469,7 +469,7 @@ pub enum IncomingError<TTransErr> {
|
||||
impl<TTransErr> fmt::Display for IncomingError<TTransErr>
|
||||
where TTransErr: fmt::Display
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
IncomingError::Transport(err) => write!(f, "{}", err),
|
||||
IncomingError::DeniedLowerPriority => {
|
||||
@ -495,7 +495,7 @@ where TTransErr: error::Error + 'static
|
||||
}
|
||||
|
||||
/// A new connection arrived on a listener.
|
||||
pub struct IncomingConnectionEvent<'a, TTrans: 'a, TInEvent: 'a, TOutEvent: 'a, THandler: 'a, THandlerErr: 'a, TPeerId: 'a>
|
||||
pub struct IncomingConnectionEvent<'a, TTrans, TInEvent, TOutEvent, THandler, THandlerErr, TPeerId>
|
||||
where TTrans: Transport
|
||||
{
|
||||
/// The produced upgrade.
|
||||
@ -537,7 +537,7 @@ where
|
||||
|
||||
/// Same as `accept`, but accepts a closure that turns a `IncomingInfo` into a handler.
|
||||
pub fn accept_with_builder<TBuilder>(self, builder: TBuilder)
|
||||
where TBuilder: FnOnce(IncomingInfo) -> THandler
|
||||
where TBuilder: FnOnce(IncomingInfo<'_>) -> THandler
|
||||
{
|
||||
let connected_point = self.to_connected_point();
|
||||
let handler = builder(self.info());
|
||||
@ -565,7 +565,7 @@ where TTrans: Transport
|
||||
{
|
||||
/// Returns the `IncomingInfo` corresponding to this incoming connection.
|
||||
#[inline]
|
||||
pub fn info(&self) -> IncomingInfo {
|
||||
pub fn info(&self) -> IncomingInfo<'_> {
|
||||
IncomingInfo {
|
||||
listen_addr: &self.listen_addr,
|
||||
send_back_addr: &self.send_back_addr,
|
||||
@ -817,7 +817,7 @@ where
|
||||
/// Returns the list of incoming connections that are currently in the process of being
|
||||
/// negotiated. We don't know the `PeerId` of these nodes yet.
|
||||
#[inline]
|
||||
pub fn incoming_negotiated(&self) -> impl Iterator<Item = IncomingInfo> {
|
||||
pub fn incoming_negotiated(&self) -> impl Iterator<Item = IncomingInfo<'_>> {
|
||||
self.reach_attempts
|
||||
.other_reach_attempts
|
||||
.iter()
|
||||
@ -844,7 +844,7 @@ where
|
||||
|
||||
/// Grants access to a struct that represents a peer.
|
||||
#[inline]
|
||||
pub fn peer(&mut self, peer_id: TPeerId) -> Peer<TTrans, TInEvent, TOutEvent, THandler, THandlerErr, TPeerId> {
|
||||
pub fn peer(&mut self, peer_id: TPeerId) -> Peer<'_, TTrans, TInEvent, TOutEvent, THandler, THandlerErr, TPeerId> {
|
||||
if peer_id == self.reach_attempts.local_peer_id {
|
||||
return Peer::LocalNode;
|
||||
}
|
||||
@ -929,7 +929,7 @@ where
|
||||
}
|
||||
|
||||
/// Provides an API similar to `Stream`, except that it cannot error.
|
||||
pub fn poll(&mut self) -> Async<RawSwarmEvent<TTrans, TInEvent, TOutEvent, THandler, THandlerErr, TPeerId>>
|
||||
pub fn poll(&mut self) -> Async<RawSwarmEvent<'_, TTrans, TInEvent, TOutEvent, THandler, THandlerErr, TPeerId>>
|
||||
where
|
||||
TTrans: Transport<Output = (TPeerId, TMuxer)>,
|
||||
TTrans::Error: Send + 'static,
|
||||
@ -1073,7 +1073,7 @@ impl<THandler, TPeerId> Default for ActionItem<THandler, TPeerId> {
|
||||
/// > panics will likely happen.
|
||||
fn handle_node_reached<'a, TTrans, TMuxer, TInEvent, TOutEvent, THandler, THandlerErr, TPeerId>(
|
||||
reach_attempts: &mut ReachAttempts<TPeerId>,
|
||||
event: CollectionReachEvent<TInEvent, TOutEvent, THandler, InternalReachErr<TTrans::Error, TPeerId>, THandlerErr, TPeerId>,
|
||||
event: CollectionReachEvent<'_, TInEvent, TOutEvent, THandler, InternalReachErr<TTrans::Error, TPeerId>, THandlerErr, TPeerId>,
|
||||
) -> (ActionItem<THandler, TPeerId>, RawSwarmEvent<'a, TTrans, TInEvent, TOutEvent, THandler, THandlerErr, TPeerId>)
|
||||
where
|
||||
TTrans: Transport<Output = (TPeerId, TMuxer)> + Clone,
|
||||
@ -1358,7 +1358,7 @@ where
|
||||
TTrans: Transport,
|
||||
TPeerId: Eq + Hash + fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
match *self {
|
||||
Peer::Connected( PeerConnected { ref peer_id, ref connected_points, .. }) => {
|
||||
f.debug_struct("Connected")
|
||||
@ -1515,7 +1515,7 @@ where
|
||||
}
|
||||
|
||||
/// Access to a peer we are connected to.
|
||||
pub struct PeerConnected<'a, TTrans: 'a, TInEvent: 'a, TOutEvent: 'a, THandler: 'a, THandlerErr: 'a, TPeerId: 'a>
|
||||
pub struct PeerConnected<'a, TTrans, TInEvent, TOutEvent, THandler, THandlerErr, TPeerId>
|
||||
where TTrans: Transport,
|
||||
{
|
||||
/// Reference to the `active_nodes` of the parent.
|
||||
@ -1571,7 +1571,7 @@ where
|
||||
|
||||
/// Access to a peer we are attempting to connect to.
|
||||
#[derive(Debug)]
|
||||
pub struct PeerPendingConnect<'a, TTrans: 'a, TInEvent: 'a, TOutEvent: 'a, THandler: 'a, THandlerErr: 'a, TPeerId: 'a>
|
||||
pub struct PeerPendingConnect<'a, TTrans, TInEvent, TOutEvent, THandler, THandlerErr, TPeerId>
|
||||
where
|
||||
TTrans: Transport
|
||||
{
|
||||
@ -1635,7 +1635,7 @@ where
|
||||
}
|
||||
|
||||
/// Access to a peer we're not connected to.
|
||||
pub struct PeerNotConnected<'a, TTrans: 'a, TInEvent: 'a, TOutEvent: 'a, THandler: 'a, THandlerErr: 'a, TPeerId: 'a>
|
||||
pub struct PeerNotConnected<'a, TTrans, TInEvent, TOutEvent, THandler, THandlerErr, TPeerId>
|
||||
where
|
||||
TTrans: Transport,
|
||||
{
|
||||
@ -1649,7 +1649,7 @@ where
|
||||
TTrans: Transport,
|
||||
TPeerId: fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
||||
f.debug_struct("PeerNotConnected")
|
||||
.field("peer_id", &self.peer_id)
|
||||
.finish()
|
||||
|
Reference in New Issue
Block a user