mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-06-27 08:41:36 +00:00
Make Multiaddr::iter
borrow data (#478)
* Use `unsigned-varint` crate. * Implement `Display` for `Protocol`. Gives `ToString` for free. * Use `Cow` in `AddrComponent`. * Add `AddrComponent::acquire`. * Document `AddrComponent::acquire`.
This commit is contained in:
@ -284,13 +284,11 @@ pub struct PeerIdTransportOutput<S> {
|
||||
// If the multiaddress is in the form `/p2p/...`, turn it into a `PeerId`.
|
||||
// Otherwise, return it as-is.
|
||||
fn multiaddr_to_peerid(addr: Multiaddr) -> Result<PeerId, Multiaddr> {
|
||||
let components = addr.iter().collect::<Vec<_>>();
|
||||
if components.len() < 1 {
|
||||
return Err(addr);
|
||||
if addr.iter().next().is_none() {
|
||||
return Err(addr)
|
||||
}
|
||||
|
||||
match components.last() {
|
||||
Some(&AddrComponent::P2P(ref peer_id)) => {
|
||||
match addr.iter().last() {
|
||||
Some(AddrComponent::P2P(ref peer_id)) => {
|
||||
match PeerId::from_multihash(peer_id.clone()) {
|
||||
Ok(peer_id) => Ok(peer_id),
|
||||
Err(_) => Err(addr),
|
||||
|
Reference in New Issue
Block a user