diff --git a/core/src/either.rs b/core/src/either.rs index 13fa1143..ab484891 100644 --- a/core/src/either.rs +++ b/core/src/either.rs @@ -34,7 +34,7 @@ where A: fmt::Display, B: fmt::Display { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { EitherError::A(a) => a.fmt(f), EitherError::B(b) => b.fmt(f) diff --git a/core/src/keys_proto.rs b/core/src/keys_proto.rs index 745df110..f7460bd4 100644 --- a/core/src/keys_proto.rs +++ b/core/src/keys_proto.rs @@ -103,7 +103,7 @@ impl ::protobuf::Message for PublicKey { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -136,7 +136,7 @@ impl ::protobuf::Message for PublicKey { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { if let Some(v) = self.Type { os.write_enum(1, v.value())?; } @@ -159,13 +159,13 @@ impl ::protobuf::Message for PublicKey { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -224,13 +224,13 @@ impl ::protobuf::Clear for PublicKey { } impl ::std::fmt::Debug for PublicKey { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for PublicKey { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -317,7 +317,7 @@ impl ::protobuf::Message for PrivateKey { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -350,7 +350,7 @@ impl ::protobuf::Message for PrivateKey { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { if let Some(v) = self.Type { os.write_enum(1, v.value())?; } @@ -373,13 +373,13 @@ impl ::protobuf::Message for PrivateKey { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -438,13 +438,13 @@ impl ::protobuf::Clear for PrivateKey { } impl ::std::fmt::Debug for PrivateKey { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for PrivateKey { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -502,7 +502,7 @@ impl ::std::default::Default for KeyType { } impl ::protobuf::reflect::ProtobufValue for KeyType { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) } } diff --git a/core/src/lib.rs b/core/src/lib.rs index 1fd0b81c..89c11135 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -63,7 +63,7 @@ /// Multi-address re-export. -pub extern crate multiaddr; +pub use multiaddr; mod keys_proto; mod peer_id; diff --git a/core/src/muxing.rs b/core/src/muxing.rs index d94c1f71..980d0a17 100644 --- a/core/src/muxing.rs +++ b/core/src/muxing.rs @@ -303,7 +303,7 @@ where P::Target: StreamMuxer, ::Substream: fmt::Debug, { - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!(f, "Substream({:?})", self.substream) } } @@ -398,7 +398,7 @@ where /// Abstract `StreamMuxer`. pub struct StreamMuxerBox { - inner: Box + Send + Sync>, + inner: Box + Send + Sync>, } impl StreamMuxerBox { diff --git a/core/src/nodes/collection.rs b/core/src/nodes/collection.rs index 44d75fa0..ff4d5802 100644 --- a/core/src/nodes/collection.rs +++ b/core/src/nodes/collection.rs @@ -51,7 +51,7 @@ impl 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> { + pub fn peer_mut(&mut self, id: &TPeerId) -> Option> { 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> { + pub fn poll(&mut self) -> Async> { 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>, nodes: &'a mut FnvHashMap, diff --git a/core/src/nodes/handled_node.rs b/core/src/nodes/handled_node.rs index c753a541..28480889 100644 --- a/core/src/nodes/handled_node.rs +++ b/core/src/nodes/handled_node.rs @@ -173,7 +173,7 @@ where TMuxer: StreamMuxer, THandler: NodeHandler> + 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 { impl fmt::Display for HandledNodeError 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), diff --git a/core/src/nodes/handled_node_tasks.rs b/core/src/nodes/handled_node_tasks.rs index def5ab5a..428513cd 100644 --- a/core/src/nodes/handled_node_tasks.rs +++ b/core/src/nodes/handled_node_tasks.rs @@ -68,7 +68,7 @@ pub struct HandledNodesTasks + Send>; 8]>, + to_spawn: SmallVec<[Box + Send>; 8]>, /// Sender to emit events to the outside. Meant to be cloned and sent to tasks. events_tx: mpsc::UnboundedSender<(InToExtMessage, TaskId)>, @@ -79,7 +79,7 @@ pub struct HandledNodesTasks fmt::Debug for HandledNodesTasks { - 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 /// /// Returns `None` if the task id is invalid. #[inline] - pub fn task(&mut self, id: TaskId) -> Option> { + pub fn task(&mut self, id: TaskId) -> Option> { match self.tasks.entry(id) { Entry::Occupied(inner) => Some(Task { inner }), Entry::Vacant(_) => None, @@ -316,7 +316,7 @@ impl } /// Access to a task in the collection. -pub struct Task<'a, TInEvent: 'a> { +pub struct Task<'a, TInEvent> { inner: OccupiedEntry<'a, TaskId, mpsc::UnboundedSender>, } @@ -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() diff --git a/core/src/nodes/listeners.rs b/core/src/nodes/listeners.rs index 440274fe..19764448 100644 --- a/core/src/nodes/listeners.rs +++ b/core/src/nodes/listeners.rs @@ -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 fmt::Debug for ListenersStream 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::>()) @@ -251,7 +247,7 @@ where TTrans: Transport, ::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; diff --git a/core/src/nodes/node.rs b/core/src/nodes/node.rs index 19afbe40..b95963d0 100644 --- a/core/src/nodes/node.rs +++ b/core/src/nodes/node.rs @@ -322,7 +322,7 @@ impl fmt::Debug for NodeStream 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") diff --git a/core/src/nodes/raw_swarm.rs b/core/src/nodes/raw_swarm.rs index 42221d0a..192f5eeb 100644 --- a/core/src/nodes/raw_swarm.rs +++ b/core/src/nodes/raw_swarm.rs @@ -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 fmt::Debug for ReachAttempts 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 { impl fmt::Display for UnknownPeerDialErr 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 { impl fmt::Display for IncomingError 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(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 { + pub fn incoming_negotiated(&self) -> impl Iterator> { 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 { + 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> + pub fn poll(&mut self) -> Async> where TTrans: Transport, TTrans::Error: Send + 'static, @@ -1073,7 +1073,7 @@ impl Default for ActionItem { /// > panics will likely happen. fn handle_node_reached<'a, TTrans, TMuxer, TInEvent, TOutEvent, THandler, THandlerErr, TPeerId>( reach_attempts: &mut ReachAttempts, - event: CollectionReachEvent, THandlerErr, TPeerId>, + event: CollectionReachEvent<'_, TInEvent, TOutEvent, THandler, InternalReachErr, THandlerErr, TPeerId>, ) -> (ActionItem, RawSwarmEvent<'a, TTrans, TInEvent, TOutEvent, THandler, THandlerErr, TPeerId>) where TTrans: Transport + 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() diff --git a/core/src/peer_id.rs b/core/src/peer_id.rs index c4920c5e..fed163f9 100644 --- a/core/src/peer_id.rs +++ b/core/src/peer_id.rs @@ -34,7 +34,7 @@ pub struct PeerId { } impl fmt::Debug for PeerId { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "PeerId({})", self.to_base58()) } } diff --git a/core/src/protocols_handler/mod.rs b/core/src/protocols_handler/mod.rs index 954cb78e..37c8de94 100644 --- a/core/src/protocols_handler/mod.rs +++ b/core/src/protocols_handler/mod.rs @@ -342,7 +342,7 @@ impl fmt::Display for ProtocolsHandlerUpgrErr where TUpgrErr: fmt::Display, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { ProtocolsHandlerUpgrErr::Timeout => { write!(f, "Timeout error while opening a substream") diff --git a/core/src/swarm.rs b/core/src/swarm.rs index efb1631a..73c81a1f 100644 --- a/core/src/swarm.rs +++ b/core/src/swarm.rs @@ -373,7 +373,7 @@ pub trait NetworkBehaviour { /// Polls for things that swarm should do. /// /// This API mimics the API of the `Stream` trait. - fn poll(&mut self, topology: &mut PollParameters) -> Async::Handler as ProtocolsHandler>::InEvent, Self::OutEvent>>; + fn poll(&mut self, topology: &mut PollParameters<'_>) -> Async::Handler as ProtocolsHandler>::InEvent, Self::OutEvent>>; } /// Used when deriving `NetworkBehaviour`. When deriving `NetworkBehaviour`, must be implemented @@ -591,7 +591,7 @@ mod tests { fn inject_node_event(&mut self, _: PeerId, _: ::OutEvent) {} - fn poll(&mut self, _: &mut PollParameters) -> + fn poll(&mut self, _: &mut PollParameters<'_>) -> Async::InEvent, Self::OutEvent>> { diff --git a/core/src/tests/dummy_transport.rs b/core/src/tests/dummy_transport.rs index 485a581e..15c3be6e 100644 --- a/core/src/tests/dummy_transport.rs +++ b/core/src/tests/dummy_transport.rs @@ -69,9 +69,9 @@ impl DummyTransport { impl Transport for DummyTransport { type Output = (PeerId, DummyMuxer); type Error = io::Error; - type Listener = Box + Send>; + type Listener = Box + Send>; type ListenerUpgrade = FutureResult; - type Dial = Box + Send>; + type Dial = Box + Send>; fn listen_on(self, addr: Multiaddr) -> Result<(Self::Listener, Multiaddr), TransportError> where diff --git a/core/src/transport/boxed.rs b/core/src/transport/boxed.rs index 66d00939..13d47969 100644 --- a/core/src/transport/boxed.rs +++ b/core/src/transport/boxed.rs @@ -37,9 +37,9 @@ where } } -pub type Dial = Box + Send>; -pub type Listener = Box, Multiaddr), Error = E> + Send>; -pub type ListenerUpgrade = Box + Send>; +pub type Dial = Box + Send>; +pub type Listener = Box, Multiaddr), Error = E> + Send>; +pub type ListenerUpgrade = Box + Send>; trait Abstract { fn listen_on(&self, addr: Multiaddr) -> Result<(Listener, Multiaddr), TransportError>; @@ -76,11 +76,11 @@ where /// See the `Transport::boxed` method. pub struct Boxed { - inner: Arc + Send + Sync>, + inner: Arc + Send + Sync>, } impl fmt::Debug for Boxed { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "BoxedTransport") } } diff --git a/core/src/transport/memory.rs b/core/src/transport/memory.rs index d97bafd6..d379a4fd 100644 --- a/core/src/transport/memory.rs +++ b/core/src/transport/memory.rs @@ -53,9 +53,9 @@ impl Clone for Dialer { impl Transport for Dialer { type Output = Channel; type Error = MemoryTransportError; - type Listener = Box + Send>; + type Listener = Box + Send>; type ListenerUpgrade = FutureResult; - type Dial = Box + Send>; + type Dial = Box + Send>; fn listen_on(self, addr: Multiaddr) -> Result<(Self::Listener, Multiaddr), TransportError> { Err(TransportError::MultiaddrNotSupported(addr)) @@ -92,7 +92,7 @@ pub enum MemoryTransportError { } impl fmt::Display for MemoryTransportError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { MemoryTransportError::RemoteClosed => write!(f, "The other side of the memory transport has been closed."), @@ -114,9 +114,9 @@ impl Clone for Listener { impl Transport for Listener { type Output = Channel; type Error = MemoryTransportError; - type Listener = Box + Send>; + type Listener = Box + Send>; type ListenerUpgrade = FutureResult; - type Dial = Box + Send>; + type Dial = Box + Send>; fn listen_on(self, addr: Multiaddr) -> Result<(Self::Listener, Multiaddr), TransportError> { if !is_memory_addr(&addr) { diff --git a/core/src/transport/mod.rs b/core/src/transport/mod.rs index 0c093bca..e82dcc18 100644 --- a/core/src/transport/mod.rs +++ b/core/src/transport/mod.rs @@ -246,7 +246,7 @@ impl TransportError { impl fmt::Display for TransportError where TErr: fmt::Display, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { TransportError::MultiaddrNotSupported(addr) => write!(f, "Multiaddr is not supported: {}", addr), TransportError::Other(err) => write!(f, "{}", err), diff --git a/core/src/transport/timeout.rs b/core/src/transport/timeout.rs index 1ca40bbc..3b3b5639 100644 --- a/core/src/transport/timeout.rs +++ b/core/src/transport/timeout.rs @@ -183,7 +183,7 @@ pub enum TransportTimeoutError { impl fmt::Display for TransportTimeoutError where TErr: fmt::Display, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { TransportTimeoutError::Timeout => write!(f, "Timeout has been reached"), TransportTimeoutError::TimerError => write!(f, "Error in the timer"), diff --git a/core/src/transport/upgrade.rs b/core/src/transport/upgrade.rs index e511313e..5fea8cda 100644 --- a/core/src/transport/upgrade.rs +++ b/core/src/transport/upgrade.rs @@ -94,7 +94,7 @@ where TTransErr: fmt::Display, TUpgrErr: fmt::Display, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { TransportUpgradeError::Transport(e) => write!(f, "Transport error: {}", e), TransportUpgradeError::Upgrade(e) => write!(f, "Upgrade error: {}", e), diff --git a/core/src/upgrade/error.rs b/core/src/upgrade/error.rs index 605c21db..6dd3082e 100644 --- a/core/src/upgrade/error.rs +++ b/core/src/upgrade/error.rs @@ -53,7 +53,7 @@ impl fmt::Display for UpgradeError where E: fmt::Display { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { UpgradeError::Select(e) => write!(f, "select error: {}", e), UpgradeError::Apply(e) => write!(f, "upgrade apply error: {}", e), diff --git a/core/src/upgrade/transfer.rs b/core/src/upgrade/transfer.rs index 5bc6d5a8..1134c5cb 100644 --- a/core/src/upgrade/transfer.rs +++ b/core/src/upgrade/transfer.rs @@ -262,7 +262,7 @@ impl From for ReadOneError { } impl fmt::Display for ReadOneError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { ReadOneError::Io(ref err) => write!(f, "{}", err), ReadOneError::TooLarge { .. } => write!(f, "Received data size over maximum"), diff --git a/examples/chat.rs b/examples/chat.rs index a3e173d3..28e7be53 100644 --- a/examples/chat.rs +++ b/examples/chat.rs @@ -49,12 +49,6 @@ //! //! The two nodes then connect. -extern crate env_logger; -extern crate futures; -extern crate libp2p; -extern crate tokio; -extern crate void; - use futures::prelude::*; use libp2p::{ NetworkBehaviour, diff --git a/examples/ipfs-kad.rs b/examples/ipfs-kad.rs index b822e1e6..ab511d00 100644 --- a/examples/ipfs-kad.rs +++ b/examples/ipfs-kad.rs @@ -23,11 +23,6 @@ //! You can pass as parameter a base58 peer ID to search for. If you don't pass any parameter, a //! peer ID will be generated randomly. -extern crate futures; -extern crate libp2p; -extern crate rand; -extern crate tokio; - use futures::prelude::*; use libp2p::{ core::PublicKey, diff --git a/examples/mdns-passive-discovery.rs b/examples/mdns-passive-discovery.rs index 2a17994b..32c760e9 100644 --- a/examples/mdns-passive-discovery.rs +++ b/examples/mdns-passive-discovery.rs @@ -18,11 +18,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -extern crate futures; -extern crate libp2p; -extern crate rand; -extern crate tokio; - use futures::prelude::*; use libp2p::mdns::service::{MdnsPacket, MdnsService}; use std::io; diff --git a/misc/core-derive/src/lib.rs b/misc/core-derive/src/lib.rs index 14660277..3e2c3d17 100644 --- a/misc/core-derive/src/lib.rs +++ b/misc/core-derive/src/lib.rs @@ -21,13 +21,10 @@ #![recursion_limit = "256"] extern crate proc_macro; -#[macro_use] -extern crate syn; -#[macro_use] -extern crate quote; -use self::proc_macro::TokenStream; -use syn::{DeriveInput, Data, DataStruct, Ident}; +use quote::quote; +use proc_macro::TokenStream; +use syn::{parse_macro_input, DeriveInput, Data, DataStruct, Ident}; /// The interface that satisfies Rust. #[proc_macro_derive(NetworkBehaviour, attributes(behaviour))] diff --git a/misc/core-derive/tests/test.rs b/misc/core-derive/tests/test.rs index 34270de6..a44a100f 100644 --- a/misc/core-derive/tests/test.rs +++ b/misc/core-derive/tests/test.rs @@ -18,9 +18,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -#[macro_use] -extern crate libp2p; -extern crate void; +use libp2p_core_derive::*; /// Small utility to check that a type implements `NetworkBehaviour`. #[allow(dead_code)] diff --git a/misc/mdns/src/behaviour.rs b/misc/mdns/src/behaviour.rs index 6a7b835c..01ae4437 100644 --- a/misc/mdns/src/behaviour.rs +++ b/misc/mdns/src/behaviour.rs @@ -103,7 +103,7 @@ impl ExactSizeIterator for DiscoveredAddrsIter { } impl fmt::Debug for DiscoveredAddrsIter { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("DiscoveredAddrsIter") .finish() } @@ -132,7 +132,7 @@ impl ExactSizeIterator for ExpiredAddrsIter { } impl fmt::Debug for ExpiredAddrsIter { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("ExpiredAddrsIter") .finish() } @@ -172,7 +172,7 @@ where fn poll( &mut self, - params: &mut PollParameters, + params: &mut PollParameters<'_>, ) -> Async< NetworkBehaviourAction< ::InEvent, @@ -277,7 +277,7 @@ where } impl fmt::Debug for Mdns { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("Mdns") .field("service", &self.service) .finish() diff --git a/misc/mdns/src/dns.rs b/misc/mdns/src/dns.rs index d7642b2e..da4e1e50 100644 --- a/misc/mdns/src/dns.rs +++ b/misc/mdns/src/dns.rs @@ -29,7 +29,7 @@ use std::{borrow::Cow, cmp, error, fmt, str, time::Duration}; /// Decodes a `` (as defined by RFC1035) into a `Vec` of ASCII characters. // TODO: better error type? -pub fn decode_character_string(mut from: &[u8]) -> Result, ()> { +pub fn decode_character_string(mut from: &[u8]) -> Result, ()> { if from.is_empty() { return Ok(Cow::Owned(Vec::new())); } @@ -317,7 +317,7 @@ pub enum MdnsResponseError { } impl fmt::Display for MdnsResponseError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { MdnsResponseError::TxtRecordTooLong => { write!(f, "TXT record invalid because it is too long") diff --git a/misc/mdns/src/lib.rs b/misc/mdns/src/lib.rs index b25a4b31..767ef9d0 100644 --- a/misc/mdns/src/lib.rs +++ b/misc/mdns/src/lib.rs @@ -30,23 +30,6 @@ //! struct will automatically discover other libp2p nodes on the local network. //! -extern crate data_encoding; -extern crate dns_parser; -extern crate futures; -extern crate libp2p_core; -extern crate multiaddr; -extern crate net2; -extern crate rand; -extern crate smallvec; -extern crate tokio_io; -extern crate tokio_reactor; -extern crate tokio_timer; -extern crate tokio_udp; -extern crate void; - -#[cfg(test)] -extern crate tokio; - /// Hardcoded name of the mDNS service. Part of the mDNS libp2p specifications. const SERVICE_NAME: &[u8] = b"_p2p._udp.local"; /// Hardcoded name of the service used for DNS-SD. diff --git a/misc/mdns/src/service.rs b/misc/mdns/src/service.rs index da877066..d668b59d 100644 --- a/misc/mdns/src/service.rs +++ b/misc/mdns/src/service.rs @@ -18,20 +18,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -extern crate data_encoding; -extern crate dns_parser; -extern crate futures; -extern crate libp2p_core; -extern crate multiaddr; -extern crate net2; -extern crate rand; -extern crate tokio_reactor; -extern crate tokio_timer; -extern crate tokio_udp; - -#[cfg(test)] -extern crate tokio; - use crate::{SERVICE_NAME, META_QUERY_SERVICE, dns}; use dns_parser::{Packet, RData}; use futures::{prelude::*, task}; @@ -66,9 +52,6 @@ pub use dns::MdnsResponseError; /// # Example /// /// ```rust -/// # extern crate futures; -/// # extern crate libp2p_core; -/// # extern crate libp2p_mdns; /// # use futures::prelude::*; /// # use libp2p_mdns::service::{MdnsService, MdnsPacket}; /// # use std::{io, time::Duration}; @@ -173,7 +156,7 @@ impl MdnsService { } /// Polls the service for packets. - pub fn poll(&mut self) -> Async { + pub fn poll(&mut self) -> Async> { // Send a query every time `query_interval` fires. // Note that we don't use a loop here—it is pretty unlikely that we need it, and there is // no point in sending multiple requests in a row. @@ -302,7 +285,7 @@ impl MdnsService { } impl fmt::Debug for MdnsService { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("MdnsService") .field("silent", &self.silent) .finish() @@ -363,7 +346,7 @@ impl<'a> MdnsQuery<'a> { } impl<'a> fmt::Debug for MdnsQuery<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("MdnsQuery") .field("from", self.remote_addr()) .field("query_id", &self.query_id) @@ -397,7 +380,7 @@ impl<'a> MdnsServiceDiscovery<'a> { } impl<'a> fmt::Debug for MdnsServiceDiscovery<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("MdnsServiceDiscovery") .field("from", self.remote_addr()) .field("query_id", &self.query_id) @@ -464,7 +447,7 @@ impl<'a> MdnsResponse<'a> { } impl<'a> fmt::Debug for MdnsResponse<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("MdnsResponse") .field("from", self.remote_addr()) .finish() @@ -544,7 +527,7 @@ impl<'a> MdnsPeer<'a> { } impl<'a> fmt::Debug for MdnsPeer<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("MdnsPeer") .field("peer_id", &self.peer_id) .finish() diff --git a/misc/multiaddr/src/errors.rs b/misc/multiaddr/src/errors.rs index 557a0bd8..4330226f 100644 --- a/misc/multiaddr/src/errors.rs +++ b/misc/multiaddr/src/errors.rs @@ -20,7 +20,7 @@ pub enum Error { } impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Error::DataLessThanLen => f.write_str("we have less data than indicated by length"), Error::InvalidMultiaddr => f.write_str("invalid multiaddr"), diff --git a/misc/multiaddr/src/lib.rs b/misc/multiaddr/src/lib.rs index 7a695ab9..31ac8fdd 100644 --- a/misc/multiaddr/src/lib.rs +++ b/misc/multiaddr/src/lib.rs @@ -3,14 +3,7 @@ ///! Implementation of [multiaddr](https://github.com/jbenet/multiaddr) ///! in Rust. -#[macro_use] -extern crate arrayref; -extern crate bs58; -extern crate byteorder; -extern crate data_encoding; -extern crate serde; -extern crate unsigned_varint; -pub extern crate multihash; +pub use multihash; mod protocol; mod errors; @@ -60,7 +53,7 @@ impl<'de> Deserialize<'de> for Multiaddr { impl<'de> de::Visitor<'de> for Visitor { type Value = Multiaddr; - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter.write_str("multiaddress") } fn visit_str(self, v: &str) -> StdResult { @@ -93,7 +86,7 @@ impl<'de> Deserialize<'de> for Multiaddr { impl fmt::Debug for Multiaddr { #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.to_string().fmt(f) } } @@ -111,7 +104,7 @@ impl fmt::Display for Multiaddr { /// ``` /// #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { for s in self.iter() { s.to_string().fmt(f)?; } @@ -185,7 +178,7 @@ impl Multiaddr { /// ``` /// #[inline] - pub fn append(&mut self, p: Protocol) { + pub fn append(&mut self, p: Protocol<'_>) { let n = self.bytes.len(); let mut w = io::Cursor::new(&mut self.bytes); w.set_position(n as u64); @@ -267,7 +260,7 @@ impl Multiaddr { /// ``` /// #[inline] - pub fn iter(&self) -> Iter { + pub fn iter(&self) -> Iter<'_> { Iter(&self.bytes) } diff --git a/misc/multiaddr/src/protocol.rs b/misc/multiaddr/src/protocol.rs index 746fbcd5..8755a940 100644 --- a/misc/multiaddr/src/protocol.rs +++ b/misc/multiaddr/src/protocol.rs @@ -1,3 +1,5 @@ + +use arrayref::array_ref; use bs58; use byteorder::{BigEndian, ByteOrder, ReadBytesExt, WriteBytesExt}; use crate::{Result, Error}; @@ -350,7 +352,7 @@ impl<'a> Protocol<'a> { } impl<'a> fmt::Display for Protocol<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { use self::Protocol::*; match self { Dccp(port) => write!(f, "/dccp/{}", port), diff --git a/misc/multiaddr/tests/lib.rs b/misc/multiaddr/tests/lib.rs index 68a38ba3..e53b2eae 100644 --- a/misc/multiaddr/tests/lib.rs +++ b/misc/multiaddr/tests/lib.rs @@ -1,11 +1,3 @@ -extern crate bs58; -extern crate bincode; -extern crate data_encoding; -extern crate parity_multiaddr; -extern crate multihash; -extern crate quickcheck; -extern crate rand; -extern crate serde_json; use data_encoding::HEXUPPER; use multihash::Multihash; @@ -108,7 +100,7 @@ impl Arbitrary for SubString { // other unit tests -fn ma_valid(source: &str, target: &str, protocols: Vec) { +fn ma_valid(source: &str, target: &str, protocols: Vec>) { let parsed = source.parse::().unwrap(); assert_eq!(HEXUPPER.encode(&parsed.to_bytes()[..]), target); assert_eq!(parsed.iter().collect::>(), protocols); diff --git a/misc/multihash/src/errors.rs b/misc/multihash/src/errors.rs index ea25e4a2..523c4081 100644 --- a/misc/multihash/src/errors.rs +++ b/misc/multihash/src/errors.rs @@ -9,7 +9,7 @@ pub enum EncodeError { impl fmt::Display for EncodeError { #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { EncodeError::UnsupportedType => write!(f, "This type is not supported yet"), } @@ -29,7 +29,7 @@ pub enum DecodeError { impl fmt::Display for DecodeError { #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { DecodeError::BadInputLength => write!(f, "Not matching input length"), DecodeError::UnknownCode => write!(f, "Found unknown code"), @@ -52,7 +52,7 @@ pub struct DecodeOwnedError { impl fmt::Display for DecodeOwnedError { #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", self.error) } } diff --git a/misc/multihash/src/lib.rs b/misc/multihash/src/lib.rs index 18147474..d2f002b8 100644 --- a/misc/multihash/src/lib.rs +++ b/misc/multihash/src/lib.rs @@ -5,19 +5,11 @@ //! A `Multihash` is a structure that contains a hashing algorithm, plus some hashed data. //! A `MultihashRef` is the same as a `Multihash`, except that it doesn't own its data. -extern crate blake2; -extern crate rand; -extern crate sha1; -extern crate sha2; -extern crate tiny_keccak; -extern crate unsigned_varint; - mod errors; mod hashes; -use std::fmt::Write; - use sha2::Digest; +use std::fmt::Write; use tiny_keccak::Keccak; use unsigned_varint::{decode, encode}; @@ -169,7 +161,7 @@ impl Multihash { /// Builds a `MultihashRef` corresponding to this `Multihash`. #[inline] - pub fn as_ref(&self) -> MultihashRef { + pub fn as_ref(&self) -> MultihashRef<'_> { MultihashRef { bytes: &self.bytes } } diff --git a/misc/multihash/tests/lib.rs b/misc/multihash/tests/lib.rs index 4c69e010..3eea04fb 100644 --- a/misc/multihash/tests/lib.rs +++ b/misc/multihash/tests/lib.rs @@ -1,4 +1,4 @@ -extern crate parity_multihash; + use parity_multihash::*; diff --git a/misc/multistream-select/src/error.rs b/misc/multistream-select/src/error.rs index 3f96247a..62b540ec 100644 --- a/misc/multistream-select/src/error.rs +++ b/misc/multistream-select/src/error.rs @@ -66,7 +66,7 @@ impl error::Error for ProtocolChoiceError { } } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { match *self { ProtocolChoiceError::MultistreamSelectError(ref err) => Some(err), _ => None, @@ -76,7 +76,7 @@ impl error::Error for ProtocolChoiceError { impl fmt::Display for ProtocolChoiceError { #[inline] - fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!(fmt, "{}", error::Error::description(self)) } } diff --git a/misc/multistream-select/src/protocol/error.rs b/misc/multistream-select/src/protocol/error.rs index 50bbfadc..f3b859f1 100644 --- a/misc/multistream-select/src/protocol/error.rs +++ b/misc/multistream-select/src/protocol/error.rs @@ -77,7 +77,7 @@ impl error::Error for MultistreamSelectError { } } - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { match *self { MultistreamSelectError::IoError(ref err) => Some(err), _ => None, @@ -87,7 +87,7 @@ impl error::Error for MultistreamSelectError { impl fmt::Display for MultistreamSelectError { #[inline] - fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { write!(fmt, "{}", error::Error::description(self)) } } diff --git a/misc/peer-id-generator/src/main.rs b/misc/peer-id-generator/src/main.rs index ce1cfb57..cc1ebc61 100644 --- a/misc/peer-id-generator/src/main.rs +++ b/misc/peer-id-generator/src/main.rs @@ -18,11 +18,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -extern crate libp2p_core; -extern crate libp2p_secio; -extern crate num_cpus; -extern crate rand; - use libp2p_core::PeerId; use libp2p_secio::SecioKeyPair; use std::{env, str, thread, time::Duration}; diff --git a/misc/rw-stream-sink/src/lib.rs b/misc/rw-stream-sink/src/lib.rs index e5e212ae..6e1086af 100644 --- a/misc/rw-stream-sink/src/lib.rs +++ b/misc/rw-stream-sink/src/lib.rs @@ -27,10 +27,6 @@ //! > **Note**: Although this crate is hosted in the libp2p repo, it is purely a utility crate and //! > not at all specific to libp2p. -extern crate bytes; -extern crate futures; -extern crate tokio_io; - use bytes::{Buf, IntoBuf}; use futures::{Async, AsyncSink, Poll, Sink, Stream}; use std::cmp; diff --git a/protocols/floodsub/src/layer.rs b/protocols/floodsub/src/layer.rs index f7218b06..262affa3 100644 --- a/protocols/floodsub/src/layer.rs +++ b/protocols/floodsub/src/layer.rs @@ -337,7 +337,7 @@ where fn poll( &mut self, - _: &mut PollParameters, + _: &mut PollParameters<'_>, ) -> Async< NetworkBehaviourAction< ::InEvent, diff --git a/protocols/floodsub/src/lib.rs b/protocols/floodsub/src/lib.rs index 3ac1c033..2f91e97b 100644 --- a/protocols/floodsub/src/lib.rs +++ b/protocols/floodsub/src/lib.rs @@ -21,19 +21,6 @@ //! Implements the floodsub protocol, see also the: //! [spec](https://github.com/libp2p/specs/tree/master/pubsub). -extern crate bs58; -extern crate bytes; -extern crate cuckoofilter; -extern crate fnv; -extern crate futures; -extern crate libp2p_core; -extern crate protobuf; -extern crate rand; -extern crate smallvec; -extern crate tokio_codec; -extern crate tokio_io; -extern crate unsigned_varint; - pub mod protocol; mod layer; diff --git a/protocols/floodsub/src/protocol.rs b/protocols/floodsub/src/protocol.rs index 6e21579d..0f8727af 100644 --- a/protocols/floodsub/src/protocol.rs +++ b/protocols/floodsub/src/protocol.rs @@ -121,7 +121,7 @@ impl From for FloodsubDecodeError { } impl fmt::Display for FloodsubDecodeError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { FloodsubDecodeError::ReadError(ref err) => write!(f, "Error while reading from socket: {}", err), diff --git a/protocols/floodsub/src/rpc_proto.rs b/protocols/floodsub/src/rpc_proto.rs index 15670eda..2cfc54e4 100644 --- a/protocols/floodsub/src/rpc_proto.rs +++ b/protocols/floodsub/src/rpc_proto.rs @@ -102,7 +102,7 @@ impl ::protobuf::Message for RPC { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -137,7 +137,7 @@ impl ::protobuf::Message for RPC { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { for v in &self.subscriptions { os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; @@ -164,13 +164,13 @@ impl ::protobuf::Message for RPC { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -229,13 +229,13 @@ impl ::protobuf::Clear for RPC { } impl ::std::fmt::Debug for RPC { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for RPC { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -316,7 +316,7 @@ impl ::protobuf::Message for RPC_SubOpts { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -353,7 +353,7 @@ impl ::protobuf::Message for RPC_SubOpts { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { if let Some(v) = self.subscribe { os.write_bool(1, v)?; } @@ -376,13 +376,13 @@ impl ::protobuf::Message for RPC_SubOpts { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -441,13 +441,13 @@ impl ::protobuf::Clear for RPC_SubOpts { } impl ::std::fmt::Debug for RPC_SubOpts { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for RPC_SubOpts { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -608,7 +608,7 @@ impl ::protobuf::Message for Message { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -653,7 +653,7 @@ impl ::protobuf::Message for Message { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { if let Some(ref v) = self.from.as_ref() { os.write_bytes(1, &v)?; } @@ -682,13 +682,13 @@ impl ::protobuf::Message for Message { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -759,13 +759,13 @@ impl ::protobuf::Clear for Message { } impl ::std::fmt::Debug for Message { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for Message { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -904,7 +904,7 @@ impl ::protobuf::Message for TopicDescriptor { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -945,7 +945,7 @@ impl ::protobuf::Message for TopicDescriptor { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { if let Some(ref v) = self.name.as_ref() { os.write_string(1, &v)?; } @@ -975,13 +975,13 @@ impl ::protobuf::Message for TopicDescriptor { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -1046,13 +1046,13 @@ impl ::protobuf::Clear for TopicDescriptor { } impl ::std::fmt::Debug for TopicDescriptor { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for TopicDescriptor { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -1122,7 +1122,7 @@ impl ::protobuf::Message for TopicDescriptor_AuthOpts { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -1155,7 +1155,7 @@ impl ::protobuf::Message for TopicDescriptor_AuthOpts { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { if let Some(v) = self.mode { os.write_enum(1, v.value())?; } @@ -1178,13 +1178,13 @@ impl ::protobuf::Message for TopicDescriptor_AuthOpts { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -1243,13 +1243,13 @@ impl ::protobuf::Clear for TopicDescriptor_AuthOpts { } impl ::std::fmt::Debug for TopicDescriptor_AuthOpts { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for TopicDescriptor_AuthOpts { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -1307,7 +1307,7 @@ impl ::std::default::Default for TopicDescriptor_AuthOpts_AuthMode { } impl ::protobuf::reflect::ProtobufValue for TopicDescriptor_AuthOpts_AuthMode { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) } } @@ -1377,7 +1377,7 @@ impl ::protobuf::Message for TopicDescriptor_EncOpts { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -1410,7 +1410,7 @@ impl ::protobuf::Message for TopicDescriptor_EncOpts { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { if let Some(v) = self.mode { os.write_enum(1, v.value())?; } @@ -1433,13 +1433,13 @@ impl ::protobuf::Message for TopicDescriptor_EncOpts { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -1498,13 +1498,13 @@ impl ::protobuf::Clear for TopicDescriptor_EncOpts { } impl ::std::fmt::Debug for TopicDescriptor_EncOpts { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for TopicDescriptor_EncOpts { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -1562,7 +1562,7 @@ impl ::std::default::Default for TopicDescriptor_EncOpts_EncMode { } impl ::protobuf::reflect::ProtobufValue for TopicDescriptor_EncOpts_EncMode { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) } } diff --git a/protocols/identify/src/identify.rs b/protocols/identify/src/identify.rs index d8ae730c..eae6ca57 100644 --- a/protocols/identify/src/identify.rs +++ b/protocols/identify/src/identify.rs @@ -129,7 +129,7 @@ where fn poll( &mut self, - params: &mut PollParameters, + params: &mut PollParameters<'_>, ) -> Async< NetworkBehaviourAction< ::InEvent, diff --git a/protocols/identify/src/lib.rs b/protocols/identify/src/lib.rs index e31a3bce..48a9b082 100644 --- a/protocols/identify/src/lib.rs +++ b/protocols/identify/src/lib.rs @@ -65,22 +65,6 @@ //! a `IdentifySender` struct that can be used to transmit back to the remote the information about //! it. -extern crate bytes; -extern crate fnv; -#[macro_use] -extern crate futures; -extern crate libp2p_core; -extern crate log; -extern crate multiaddr; -extern crate parking_lot; -extern crate protobuf; -extern crate smallvec; -extern crate tokio_codec; -extern crate tokio_io; -extern crate tokio_timer; -extern crate unsigned_varint; -extern crate void; - pub use self::identify::{Identify, IdentifyEvent}; pub use self::id_transport::IdentifyTransport; pub use self::protocol::IdentifyInfo; diff --git a/protocols/identify/src/protocol.rs b/protocols/identify/src/protocol.rs index 65fb3af8..7ae57d4f 100644 --- a/protocols/identify/src/protocol.rs +++ b/protocols/identify/src/protocol.rs @@ -21,6 +21,7 @@ use bytes::BytesMut; use crate::structs_proto; use futures::{future::{self, FutureResult}, Async, AsyncSink, Future, Poll, Sink, Stream}; +use futures::try_ready; use libp2p_core::{ Multiaddr, PublicKey, upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo} @@ -261,12 +262,9 @@ fn parse_proto_msg(msg: BytesMut) -> Result<(IdentifyInfo, Multiaddr), IoError> #[cfg(test)] mod tests { - extern crate libp2p_tcp; - extern crate tokio; - use crate::protocol::{IdentifyInfo, RemoteInfo, IdentifyProtocolConfig}; - use self::tokio::runtime::current_thread::Runtime; - use self::libp2p_tcp::TcpConfig; + use tokio::runtime::current_thread::Runtime; + use libp2p_tcp::TcpConfig; use futures::{Future, Stream}; use libp2p_core::{PublicKey, Transport, upgrade::{apply_outbound, apply_inbound}}; use std::{io, sync::mpsc, thread}; diff --git a/protocols/identify/src/structs_proto.rs b/protocols/identify/src/structs_proto.rs index 72818e09..6524cebf 100644 --- a/protocols/identify/src/structs_proto.rs +++ b/protocols/identify/src/structs_proto.rs @@ -240,7 +240,7 @@ impl ::protobuf::Message for Identify { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -297,7 +297,7 @@ impl ::protobuf::Message for Identify { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { if let Some(ref v) = self.protocolVersion.as_ref() { os.write_string(5, &v)?; } @@ -332,13 +332,13 @@ impl ::protobuf::Message for Identify { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -421,13 +421,13 @@ impl ::protobuf::Clear for Identify { } impl ::std::fmt::Debug for Identify { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for Identify { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Message(self) } } diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index 216bf993..6c15a4b8 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -171,7 +171,7 @@ impl Kademlia { } /// Builds the answer to a request. - fn build_result(&mut self, query: QueryTarget, request_id: KademliaRequestId, parameters: &mut PollParameters) + fn build_result(&mut self, query: QueryTarget, request_id: KademliaRequestId, parameters: &mut PollParameters<'_>) -> KademliaHandlerIn { match query { @@ -444,7 +444,7 @@ where fn poll( &mut self, - parameters: &mut PollParameters, + parameters: &mut PollParameters<'_>, ) -> Async< NetworkBehaviourAction< ::InEvent, @@ -674,7 +674,7 @@ fn gen_random_id(my_id: &PeerId, bucket_num: usize) -> Result { /// > **Note**: This is just a convenience function that doesn't do anything note-worthy. fn build_kad_peer( peer_id: PeerId, - parameters: &mut PollParameters, + parameters: &mut PollParameters<'_>, kbuckets: &KBucketsTable>, connected_peers: &FnvHashSet ) -> KadPeer { diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 84399ec2..24a67f85 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -197,7 +197,7 @@ pub enum KademliaHandlerQueryErr { } impl fmt::Display for KademliaHandlerQueryErr { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { KademliaHandlerQueryErr::Upgrade(err) => { write!(f, "Error while performing Kademlia query: {}", err) diff --git a/protocols/kad/src/kbucket.rs b/protocols/kad/src/kbucket.rs index edae09de..c19aea37 100644 --- a/protocols/kad/src/kbucket.rs +++ b/protocols/kad/src/kbucket.rs @@ -181,7 +181,7 @@ where /// Ordered by proximity to the local node. Closest bucket (with max. one node in it) comes /// first. #[inline] - pub fn buckets(&mut self) -> BucketsIter { + pub fn buckets(&mut self) -> BucketsIter<'_, TPeerId, TVal> { BucketsIter(self.tables.iter_mut(), self.unresponsive_timeout) } @@ -279,7 +279,7 @@ where /// This inserts the node in the k-buckets, if possible. If it is already in a k-bucket, puts /// it above the disconnected nodes. If it is not already in a k-bucket, then the value will /// be built with the `Default` trait. - pub fn set_connected(&mut self, id: &TPeerId) -> Update + pub fn set_connected(&mut self, id: &TPeerId) -> Update<'_, TPeerId> where TVal: Default, { @@ -412,9 +412,9 @@ pub enum Update<'a, TPeerId> { } /// Iterator giving access to a bucket. -pub struct BucketsIter<'a, TPeerId: 'a, TVal: 'a>(SliceIterMut<'a, KBucket>, Duration); +pub struct BucketsIter<'a, TPeerId, TVal>(SliceIterMut<'a, KBucket>, Duration); -impl<'a, TPeerId: 'a, TVal: 'a> Iterator for BucketsIter<'a, TPeerId, TVal> { +impl<'a, TPeerId, TVal> Iterator for BucketsIter<'a, TPeerId, TVal> { type Item = Bucket<'a, TPeerId, TVal>; #[inline] @@ -431,12 +431,12 @@ impl<'a, TPeerId: 'a, TVal: 'a> Iterator for BucketsIter<'a, TPeerId, TVal> { } } -impl<'a, TPeerId: 'a, TVal: 'a> ExactSizeIterator for BucketsIter<'a, TPeerId, TVal> {} +impl<'a, TPeerId, TVal> ExactSizeIterator for BucketsIter<'a, TPeerId, TVal> {} /// Access to a bucket. -pub struct Bucket<'a, TPeerId: 'a, TVal: 'a>(&'a mut KBucket); +pub struct Bucket<'a, TPeerId, TVal>(&'a mut KBucket); -impl<'a, TPeerId: 'a, TVal: 'a> Bucket<'a, TPeerId, TVal> { +impl<'a, TPeerId, TVal> Bucket<'a, TPeerId, TVal> { /// Returns the number of entries in that bucket. /// /// > **Note**: Keep in mind that this operation can be racy. If `update()` is called on the @@ -464,8 +464,7 @@ impl<'a, TPeerId: 'a, TVal: 'a> Bucket<'a, TPeerId, TVal> { #[cfg(test)] mod tests { - extern crate rand; - use self::rand::random; + use rand::random; use crate::kbucket::{KBucketsPeerId, KBucketsTable, Update, MAX_NODES_PER_BUCKET}; use multihash::{Multihash, Hash}; use std::thread; diff --git a/protocols/kad/src/lib.rs b/protocols/kad/src/lib.rs index 2590d04c..fd34f516 100644 --- a/protocols/kad/src/lib.rs +++ b/protocols/kad/src/lib.rs @@ -56,32 +56,6 @@ // `KademliaSystem`. // -extern crate arrayvec; -extern crate bigint; -extern crate bs58; -extern crate bytes; -extern crate fnv; -#[cfg_attr(test, macro_use)] -extern crate futures; -extern crate libp2p_core; -extern crate libp2p_identify; -extern crate libp2p_ping; -extern crate log; -extern crate multiaddr; -extern crate multihash; -extern crate parking_lot; -extern crate protobuf; -extern crate rand; -extern crate smallvec; -extern crate tokio_codec; -extern crate tokio_io; -extern crate tokio_timer; -extern crate unsigned_varint; -extern crate void; - -#[cfg(test)] -extern crate tokio; - pub use self::behaviour::{Kademlia, KademliaOut}; pub use self::kbucket::KBucketsPeerId; pub use self::protocol::KadConnectionType; diff --git a/protocols/kad/src/protobuf_structs/dht.rs b/protocols/kad/src/protobuf_structs/dht.rs index c48ee327..411304ca 100644 --- a/protocols/kad/src/protobuf_structs/dht.rs +++ b/protocols/kad/src/protobuf_structs/dht.rs @@ -218,7 +218,7 @@ impl ::protobuf::Message for Message { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -282,7 +282,7 @@ impl ::protobuf::Message for Message { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { if let Some(v) = self.field_type { os.write_enum(1, v.value())?; } @@ -323,13 +323,13 @@ impl ::protobuf::Message for Message { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -412,13 +412,13 @@ impl ::protobuf::Clear for Message { } impl ::std::fmt::Debug for Message { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for Message { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -525,7 +525,7 @@ impl ::protobuf::Message for Message_Peer { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -564,7 +564,7 @@ impl ::protobuf::Message for Message_Peer { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { if let Some(ref v) = self.id.as_ref() { os.write_bytes(1, &v)?; } @@ -590,13 +590,13 @@ impl ::protobuf::Message for Message_Peer { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -661,13 +661,13 @@ impl ::protobuf::Clear for Message_Peer { } impl ::std::fmt::Debug for Message_Peer { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for Message_Peer { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -734,7 +734,7 @@ impl ::std::default::Default for Message_MessageType { } impl ::protobuf::reflect::ProtobufValue for Message_MessageType { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) } } @@ -795,7 +795,7 @@ impl ::std::default::Default for Message_ConnectionType { } impl ::protobuf::reflect::ProtobufValue for Message_ConnectionType { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Enum(self.descriptor()) } } diff --git a/protocols/kad/src/protobuf_structs/record.rs b/protocols/kad/src/protobuf_structs/record.rs index 4038ff82..59b8b020 100644 --- a/protocols/kad/src/protobuf_structs/record.rs +++ b/protocols/kad/src/protobuf_structs/record.rs @@ -225,7 +225,7 @@ impl ::protobuf::Message for Record { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -276,7 +276,7 @@ impl ::protobuf::Message for Record { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { if let Some(ref v) = self.key.as_ref() { os.write_string(1, &v)?; } @@ -308,13 +308,13 @@ impl ::protobuf::Message for Record { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -391,13 +391,13 @@ impl ::protobuf::Clear for Record { } impl ::std::fmt::Debug for Record { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for Record { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Message(self) } } diff --git a/protocols/kad/src/protocol.rs b/protocols/kad/src/protocol.rs index 75fc4482..e401e3ef 100644 --- a/protocols/kad/src/protocol.rs +++ b/protocols/kad/src/protocol.rs @@ -463,8 +463,6 @@ fn proto_to_resp_msg( #[cfg(test)] mod tests { - extern crate libp2p_tcp; - extern crate tokio; /*// TODO: restore use self::libp2p_tcp::TcpConfig; diff --git a/protocols/kad/src/query.rs b/protocols/kad/src/query.rs index 888015df..d55fcc3c 100644 --- a/protocols/kad/src/query.rs +++ b/protocols/kad/src/query.rs @@ -275,7 +275,7 @@ impl QueryState { } /// Polls this individual query. - pub fn poll(&mut self) -> Async { + pub fn poll(&mut self) -> Async> { // While iterating over peers, count the number of queries currently being processed. // This is used to not go over the limit of parallel requests. // If this is still 0 at the end of the function, that means the query is finished. @@ -468,7 +468,7 @@ enum QueryPeerState { #[cfg(test)] mod tests { use super::{QueryConfig, QueryState, QueryStatePollOut, QueryTarget}; - use futures::{self, prelude::*}; + use futures::{self, try_ready, prelude::*}; use libp2p_core::PeerId; use std::{iter, time::Duration, sync::Arc, sync::Mutex, thread}; use tokio; diff --git a/protocols/noise/src/error.rs b/protocols/noise/src/error.rs index e35fa514..e8030c66 100644 --- a/protocols/noise/src/error.rs +++ b/protocols/noise/src/error.rs @@ -35,7 +35,7 @@ pub enum NoiseError { } impl fmt::Display for NoiseError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { NoiseError::Io(e) => write!(f, "{}", e), NoiseError::Noise(e) => write!(f, "{}", e), diff --git a/protocols/noise/src/io.rs b/protocols/noise/src/io.rs index d1fb8424..e3cbb3bc 100644 --- a/protocols/noise/src/io.rs +++ b/protocols/noise/src/io.rs @@ -44,7 +44,7 @@ struct BufferBorrow<'a> { impl Buffer { /// Create a mutable borrow by splitting the buffer slice. - fn borrow_mut(&mut self) -> BufferBorrow { + fn borrow_mut(&mut self) -> BufferBorrow<'_> { let (r, w) = self.inner.split_at_mut(2 * MAX_NOISE_PKG_LEN); let (read, read_crypto) = r.split_at_mut(MAX_NOISE_PKG_LEN); let (write, write_crypto) = w.split_at_mut(MAX_WRITE_BUF_LEN); @@ -101,7 +101,7 @@ pub struct NoiseOutput { } impl fmt::Debug for NoiseOutput { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("NoiseOutput") .field("read_state", &self.read_state) .field("write_state", &self.write_state) diff --git a/protocols/noise/src/util.rs b/protocols/noise/src/util.rs index ad648ed4..b9a55b18 100644 --- a/protocols/noise/src/util.rs +++ b/protocols/noise/src/util.rs @@ -108,7 +108,7 @@ impl snow::types::Dh for X25519 { self.keypair = Keypair::new(secret, public) } - fn generate(&mut self, rng: &mut snow::types::Random) { + fn generate(&mut self, rng: &mut dyn snow::types::Random) { let mut s = [0; 32]; rng.fill_bytes(&mut s); let secret = SecretKey::new(s); diff --git a/protocols/observed/src/lib.rs b/protocols/observed/src/lib.rs index 5230b891..86818a2e 100644 --- a/protocols/observed/src/lib.rs +++ b/protocols/observed/src/lib.rs @@ -21,13 +21,6 @@ //! Connection upgrade to allow retrieving the externally visible address (as dialer) or //! to report the externally visible address (as listener). -extern crate bytes; -extern crate futures; -extern crate libp2p_core; -extern crate tokio_codec; -extern crate tokio_io; -extern crate unsigned_varint; - use bytes::Bytes; use futures::{future, prelude::*}; use libp2p_core::{Multiaddr, upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}}; @@ -107,11 +100,9 @@ impl Sender { #[cfg(test)] mod tests { - extern crate tokio; - use libp2p_core::{Multiaddr, upgrade::{InboundUpgrade, OutboundUpgrade}}; - use self::tokio::runtime::current_thread; - use self::tokio::net::{TcpListener, TcpStream}; + use tokio::runtime::current_thread; + use tokio::net::{TcpListener, TcpStream}; use super::*; #[test] diff --git a/protocols/ping/src/lib.rs b/protocols/ping/src/lib.rs index 8e01a848..ce8740b3 100644 --- a/protocols/ping/src/lib.rs +++ b/protocols/ping/src/lib.rs @@ -113,7 +113,7 @@ where fn poll( &mut self, - _: &mut PollParameters, + _: &mut PollParameters<'_>, ) -> Async< NetworkBehaviourAction< ::InEvent, diff --git a/protocols/plaintext/src/lib.rs b/protocols/plaintext/src/lib.rs index 7b203ee8..c3ece927 100644 --- a/protocols/plaintext/src/lib.rs +++ b/protocols/plaintext/src/lib.rs @@ -18,10 +18,6 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -extern crate futures; -extern crate libp2p_core; -extern crate void; - use futures::future::{self, FutureResult}; use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; use std::iter; diff --git a/protocols/secio/src/error.rs b/protocols/secio/src/error.rs index 99ad113e..0646eae6 100644 --- a/protocols/secio/src/error.rs +++ b/protocols/secio/src/error.rs @@ -76,7 +76,7 @@ pub enum SecioError { } impl error::Error for SecioError { - fn cause(&self) -> Option<&error::Error> { + fn cause(&self) -> Option<&dyn error::Error> { match *self { SecioError::IoError(ref err) => Some(err), SecioError::Protobuf(ref err) => Some(err), @@ -91,7 +91,7 @@ impl error::Error for SecioError { impl fmt::Display for SecioError { #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { match self { SecioError::IoError(e) => write!(f, "I/O error: {}", e), diff --git a/protocols/secio/src/lib.rs b/protocols/secio/src/lib.rs index a293ec55..0b5b2425 100644 --- a/protocols/secio/src/lib.rs +++ b/protocols/secio/src/lib.rs @@ -221,7 +221,7 @@ impl SecioKeyPair { pub fn rsa_from_pkcs8

( private: &[u8], public: P, - ) -> Result> + ) -> Result> where P: Into>, { @@ -236,7 +236,7 @@ impl SecioKeyPair { } /// Generates a new Ed25519 key pair and uses it. - pub fn ed25519_generated() -> Result> { + pub fn ed25519_generated() -> Result> { let mut csprng = rand::thread_rng(); let keypair: Ed25519KeyPair = Ed25519KeyPair::generate::<_>(&mut csprng); Ok(SecioKeyPair { @@ -249,7 +249,7 @@ impl SecioKeyPair { /// Builds a `SecioKeyPair` from a raw ed25519 32 bytes private key. /// /// Returns an error if the slice doesn't have the correct length. - pub fn ed25519_raw_key(key: impl AsRef<[u8]>) -> Result> { + pub fn ed25519_raw_key(key: impl AsRef<[u8]>) -> Result> { let secret = ed25519_dalek::SecretKey::from_bytes(key.as_ref()) .map_err(|err| err.to_string())?; let public = ed25519_dalek::PublicKey::from(&secret); @@ -266,7 +266,7 @@ impl SecioKeyPair { /// Generates a new random sec256k1 key pair. #[cfg(feature = "secp256k1")] - pub fn secp256k1_generated() -> Result> { + pub fn secp256k1_generated() -> Result> { let private = secp256k1::key::SecretKey::new(&mut secp256k1::rand::thread_rng()); Ok(SecioKeyPair { inner: SecioKeyPairInner::Secp256k1 { private }, @@ -275,7 +275,7 @@ impl SecioKeyPair { /// Builds a `SecioKeyPair` from a raw secp256k1 32 bytes private key. #[cfg(feature = "secp256k1")] - pub fn secp256k1_raw_key(key: K) -> Result> + pub fn secp256k1_raw_key(key: K) -> Result> where K: AsRef<[u8]>, { @@ -288,7 +288,7 @@ impl SecioKeyPair { /// Builds a `SecioKeyPair` from a secp256k1 private key in DER format. #[cfg(feature = "secp256k1")] - pub fn secp256k1_from_der(key: K) -> Result> + pub fn secp256k1_from_der(key: K) -> Result> where K: AsRef<[u8]>, { diff --git a/protocols/secio/src/structs_proto.rs b/protocols/secio/src/structs_proto.rs index 64b06ae2..fdc4316a 100644 --- a/protocols/secio/src/structs_proto.rs +++ b/protocols/secio/src/structs_proto.rs @@ -225,7 +225,7 @@ impl ::protobuf::Message for Propose { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -276,7 +276,7 @@ impl ::protobuf::Message for Propose { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { if let Some(ref v) = self.rand.as_ref() { os.write_bytes(1, &v)?; } @@ -308,13 +308,13 @@ impl ::protobuf::Message for Propose { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -391,13 +391,13 @@ impl ::protobuf::Clear for Propose { } impl ::std::fmt::Debug for Propose { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for Propose { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Message(self) } } @@ -495,7 +495,7 @@ impl ::protobuf::Message for Exchange { true } - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { while !is.eof()? { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { @@ -528,7 +528,7 @@ impl ::protobuf::Message for Exchange { my_size } - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { if let Some(ref v) = self.epubkey.as_ref() { os.write_bytes(1, &v)?; } @@ -551,13 +551,13 @@ impl ::protobuf::Message for Exchange { &mut self.unknown_fields } - fn as_any(&self) -> &::std::any::Any { - self as &::std::any::Any + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) } - fn as_any_mut(&mut self) -> &mut ::std::any::Any { - self as &mut ::std::any::Any + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) } - fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + fn into_any(self: Box) -> ::std::boxed::Box { self } @@ -616,13 +616,13 @@ impl ::protobuf::Clear for Exchange { } impl ::std::fmt::Debug for Exchange { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { ::protobuf::text_format::fmt(self, f) } } impl ::protobuf::reflect::ProtobufValue for Exchange { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef<'_> { ::protobuf::reflect::ProtobufValueRef::Message(self) } } diff --git a/src/lib.rs b/src/lib.rs index 4bcd9e4f..ea535ea0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -132,15 +132,12 @@ #![doc(html_logo_url = "https://libp2p.io/img/logo_small.png")] #![doc(html_favicon_url = "https://libp2p.io/img/favicon.png")] -pub extern crate bytes; -pub extern crate futures; -pub extern crate multiaddr; -pub extern crate multihash; -pub extern crate tokio_io; -pub extern crate tokio_codec; - -extern crate libp2p_core_derive; -extern crate tokio_executor; +pub use bytes; +pub use futures; +pub use multiaddr::{self}; +pub use multihash; +pub use tokio_io; +pub use tokio_codec; #[doc(inline)] pub use libp2p_core as core; diff --git a/transports/dns/src/lib.rs b/transports/dns/src/lib.rs index a7a3b586..8aed3b0e 100644 --- a/transports/dns/src/lib.rs +++ b/transports/dns/src/lib.rs @@ -33,16 +33,10 @@ //! replaced with respectively an `/ip4/` or an `/ip6/` component. //! -extern crate futures; -extern crate libp2p_core as swarm; -#[macro_use] -extern crate log; -extern crate multiaddr; -extern crate tokio_dns; -extern crate tokio_io; +use libp2p_core as swarm; use futures::{future::{self, Either, FutureResult, JoinAll}, prelude::*, stream, try_ready}; -use log::Level; +use log::{debug, trace, log_enabled, Level}; use multiaddr::{Protocol, Multiaddr}; use std::{error, fmt, io, marker::PhantomData, net::IpAddr}; use swarm::{Transport, transport::TransportError}; @@ -85,7 +79,7 @@ where T: fmt::Debug, { #[inline] - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_tuple("DnsConfig").field(&self.inner).finish() } } @@ -195,7 +189,7 @@ pub enum DnsErr { impl fmt::Display for DnsErr where TErr: fmt::Display { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { DnsErr::Underlying(err) => write!(f, "{}", err), DnsErr::ResolveFail(addr) => write!(f, "Failed to resolve DNS address: {:?}", addr), @@ -322,10 +316,9 @@ where #[cfg(test)] mod tests { - extern crate libp2p_tcp; - use self::libp2p_tcp::TcpConfig; + use libp2p_tcp::TcpConfig; use futures::future; - use swarm::{Transport, transport::TransportError}; + use super::swarm::{Transport, transport::TransportError}; use multiaddr::{Protocol, Multiaddr}; use super::DnsConfig; diff --git a/transports/ratelimit/src/lib.rs b/transports/ratelimit/src/lib.rs index 9b0ea598..62129e3f 100644 --- a/transports/ratelimit/src/lib.rs +++ b/transports/ratelimit/src/lib.rs @@ -18,18 +18,11 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -extern crate aio_limited; -#[macro_use] -extern crate futures; -extern crate libp2p_core; -#[macro_use] -extern crate log; -extern crate tokio_executor; -extern crate tokio_io; - use aio_limited::{Limited, Limiter}; use futures::prelude::*; +use futures::try_ready; use libp2p_core::{Multiaddr, Transport, transport::TransportError}; +use log::error; use std::{error, fmt, io}; use tokio_executor::Executor; use tokio_io::{AsyncRead, AsyncWrite, io::{ReadHalf, WriteHalf}}; @@ -82,7 +75,7 @@ pub enum RateLimitedErr { impl fmt::Display for RateLimitedErr where TErr: fmt::Display { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { RateLimitedErr::LimiterError(err) => write!(f, "Limiter initialization error: {}", err), RateLimitedErr::Underlying(err) => write!(f, "{}", err), diff --git a/transports/tcp/src/lib.rs b/transports/tcp/src/lib.rs index c844ec60..19fd0182 100644 --- a/transports/tcp/src/lib.rs +++ b/transports/tcp/src/lib.rs @@ -38,16 +38,9 @@ //! The `TcpConfig` structs implements the `Transport` trait of the `swarm` library. See the //! documentation of `swarm` and of libp2p in general to learn how to use the `Transport` trait. -extern crate futures; -extern crate libp2p_core as swarm; -#[macro_use] -extern crate log; -extern crate multiaddr; -extern crate tk_listen; -extern crate tokio_io; -extern crate tokio_tcp; - use futures::{future, future::FutureResult, prelude::*, Async, Poll}; +use libp2p_core as swarm; +use log::{debug, error}; use multiaddr::{Protocol, Multiaddr, ToMultiaddr}; use std::fmt; use std::io::{self, Read, Write}; @@ -338,7 +331,7 @@ impl Stream for TcpListenStream { } impl fmt::Debug for TcpListenStream { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self.inner { Ok(_) => write!(f, "TcpListenStream"), Err(None) => write!(f, "TcpListenStream(Errored)"), @@ -394,15 +387,14 @@ impl Drop for TcpTransStream { #[cfg(test)] mod tests { - extern crate tokio; - use self::tokio::runtime::current_thread::Runtime; + use tokio::runtime::current_thread::Runtime; use super::{multiaddr_to_socketaddr, TcpConfig}; use futures::stream::Stream; use futures::Future; use multiaddr::Multiaddr; use std; use std::net::{IpAddr, Ipv4Addr, SocketAddr}; - use swarm::Transport; + use super::swarm::Transport; use tokio_io; #[test] diff --git a/transports/uds/src/lib.rs b/transports/uds/src/lib.rs index 9edb41e7..61500d18 100644 --- a/transports/uds/src/lib.rs +++ b/transports/uds/src/lib.rs @@ -46,22 +46,9 @@ #![cfg(all(unix, not(any(target_os = "emscripten", target_os = "unknown"))))] -extern crate futures; -extern crate libp2p_core; -#[macro_use] -extern crate log; -extern crate multiaddr; -extern crate tokio_uds; - -#[cfg(test)] -extern crate tempfile; -#[cfg(test)] -extern crate tokio_io; -#[cfg(test)] -extern crate tokio; - use futures::{future::{self, FutureResult}, prelude::*, try_ready}; use futures::stream::Stream; +use log::debug; use multiaddr::{Protocol, Multiaddr}; use std::{io, path::PathBuf}; use libp2p_core::{Transport, transport::TransportError}; diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index 1267ded4..2abda4ec 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "libp2p-websocket" +edition = "2018" description = "WebSocket transport for libp2p" version = "0.3.0" authors = ["Parity Technologies "] diff --git a/transports/websocket/src/browser.rs b/transports/websocket/src/browser.rs index 82bc10de..aa4fb549 100644 --- a/transports/websocket/src/browser.rs +++ b/transports/websocket/src/browser.rs @@ -18,6 +18,8 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +use libp2p_core as swarm; +use log::debug; use futures::{future, stream}; use futures::stream::Then as StreamThen; use futures::sync::{mpsc, oneshot}; diff --git a/transports/websocket/src/desktop.rs b/transports/websocket/src/desktop.rs index bf7bb25c..72b047be 100644 --- a/transports/websocket/src/desktop.rs +++ b/transports/websocket/src/desktop.rs @@ -19,6 +19,8 @@ // DEALINGS IN THE SOFTWARE. use futures::{Future, IntoFuture, Sink, Stream}; +use libp2p_core as swarm; +use log::{debug, trace}; use multiaddr::{Protocol, Multiaddr}; use rw_stream_sink::RwStreamSink; use std::{error, fmt}; @@ -27,8 +29,8 @@ use swarm::{Transport, transport::TransportError}; use tokio_io::{AsyncRead, AsyncWrite}; use websocket::client::builder::ClientBuilder; use websocket::message::OwnedMessage; -use websocket::server::upgrade::async::IntoWs; -use websocket::stream::async::Stream as AsyncStream; +use websocket::server::upgrade::r#async::IntoWs; +use websocket::stream::r#async::Stream as AsyncStream; /// Represents the configuration for a websocket transport capability for libp2p. Must be put on /// top of another `Transport`. @@ -67,11 +69,11 @@ where // TODO: this Send is pretty arbitrary and is necessary because of the websocket library T::Output: AsyncRead + AsyncWrite + Send, { - type Output = Box; + type Output = Box; type Error = WsError; - type Listener = Box + Send>; - type ListenerUpgrade = Box + Send>; - type Dial = Box + Send>; + type Listener = Box + Send>; + type ListenerUpgrade = Box + Send>; + type Dial = Box + Send>; fn listen_on( self, @@ -127,15 +129,15 @@ where .map(|v| v.expect("we only take while this is Some")); let read_write = RwStreamSink::new(framed_data); - Box::new(read_write) as Box + Box::new(read_write) as Box }) }) - .map(|s| Box::new(Ok(s).into_future()) as Box + Send>) + .map(|s| Box::new(Ok(s).into_future()) as Box + Send>) .into_future() .flatten() }); - (Box::new(upgraded) as Box + Send>, client_addr) + (Box::new(upgraded) as Box + Send>, client_addr) }); Ok((Box::new(listen) as Box<_>, new_addr)) @@ -189,7 +191,7 @@ where } }); let read_write = RwStreamSink::new(framed_data); - Box::new(read_write) as Box + Box::new(read_write) as Box }) }); @@ -213,7 +215,7 @@ pub enum WsError { impl fmt::Display for WsError where TErr: fmt::Display { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { WsError::WebSocket(err) => write!(f, "{}", err), WsError::Underlying(err) => write!(f, "{}", err), @@ -266,13 +268,12 @@ fn client_addr_to_ws(client_addr: &Multiaddr, is_wss: bool) -> String { #[cfg(test)] mod tests { - extern crate libp2p_tcp as tcp; - extern crate tokio; - use self::tokio::runtime::current_thread::Runtime; + use libp2p_tcp as tcp; + use tokio::runtime::current_thread::Runtime; use futures::{Future, Stream}; use multiaddr::Multiaddr; - use swarm::Transport; - use WsConfig; + use super::swarm::Transport; + use super::WsConfig; #[test] fn dialer_connects_to_listener_ipv4() { diff --git a/transports/websocket/src/lib.rs b/transports/websocket/src/lib.rs index 2837ecfd..85b36ff6 100644 --- a/transports/websocket/src/lib.rs +++ b/transports/websocket/src/lib.rs @@ -68,19 +68,9 @@ //! ``` //! -extern crate futures; -extern crate libp2p_core as swarm; -#[macro_use] -extern crate log; -extern crate multiaddr; -extern crate rw_stream_sink; -extern crate tokio_io; - #[cfg(any(target_os = "emscripten", target_os = "unknown"))] #[macro_use] extern crate stdweb; -#[cfg(not(any(target_os = "emscripten", target_os = "unknown")))] -extern crate websocket; #[cfg(any(target_os = "emscripten", target_os = "unknown"))] mod browser;