pub(crate) fn multiaddr_to_socketaddr(addr: &Multiaddr) -> Result<SocketAddr, ()> {
    let mut iter = addr.iter();
    let proto1 = iter.next().ok_or(())?;
    let proto2 = iter.next().ok_or(())?;
    let proto3 = iter.next().ok_or(())?;

    if iter.next().is_some() {
        return Err(());
    }

    match (proto1, proto2, proto3) {
        (Protocol::Ip4(ip), Protocol::Udp(port), Protocol::Quic) => {
            Ok(SocketAddr::new(ip.into(), port))
        }
        (Protocol::Ip6(ip), Protocol::Udp(port), Protocol::Quic) => {
            Ok(SocketAddr::new(ip.into(), port))
        }
        _ => Err(()),
    }
}
/// Tries to turn a QUIC multiaddress into a UDP [`SocketAddr`]. Returns an error if the format
/// of the multiaddr is wrong.
Tries to turn a QUIC multiaddress into a UDP [`SocketAddr`]. Returns an error if the format
of the multiaddr is wrong.
Tries to turn a QUIC multiaddress into a UDP [ ` SocketAddr ` ] . Returns an error if the format of the multiaddr is wrong .
pub(crate) fn multiaddr_to_socketaddr(addr: &Multiaddr) -> Result<SocketAddr, ()> {
    let mut iter = addr.iter();
    let proto1 = iter.next().ok_or(())?;
    let proto2 = iter.next().ok_or(())?;
    let proto3 = iter.next().ok_or(())?;
    if iter.next().is_some() {
        return Err(());
    }
    match (proto1, proto2, proto3) {
        (Protocol::Ip4(ip), Protocol::Udp(port), Protocol::Quic) => {
            Ok(SocketAddr::new(ip.into(), port))
        }
        (Protocol::Ip6(ip), Protocol::Udp(port), Protocol::Quic) => {
            Ok(SocketAddr::new(ip.into(), port))
        }
        _ => Err(()),
    }
}
pub ( crate ) fn multiaddr_to_socketaddr ( addr : & Multiaddr ) -> Result < SocketAddr , ( ) > { let mut iter = addr . iter ( ) ; let proto1 = iter . next ( ) . ok_or ( ( ) ) ? ; let proto2 = iter . next ( ) . ok_or ( ( ) ) ? ; let proto3 = iter . next ( ) . ok_or ( ( ) ) ? ; if iter . next ( ) . is_some ( ) { return Err ( ( ) ) ; } match ( proto1 , proto2 , proto3 ) { ( Protocol :: Ip4 ( ip ) , Protocol :: Udp ( port ) , Protocol :: Quic ) => { Ok ( SocketAddr :: new ( ip . into ( ) , port ) ) } ( Protocol :: Ip6 ( ip ) , Protocol :: Udp ( port ) , Protocol :: Quic ) => { Ok ( SocketAddr :: new ( ip . into ( ) , port ) ) } _ => Err ( ( ) ) , } }
Tries to turn a QUIC multiaddress into a UDP [`SocketAddr`].
Tries to turn a QUIC multiaddress into a UDP [ ` SocketAddr ` ] .
addr
&Multiaddr
addr
&Multiaddr