From ae0f787e03e8022b45d67c875303e24af5aaeaa1 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Mon, 18 Dec 2017 15:55:49 +0100 Subject: [PATCH] Fix concerns --- example/examples/echo-dialer.rs | 6 +++++- example/examples/echo-server.rs | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/example/examples/echo-dialer.rs b/example/examples/echo-dialer.rs index 408b13a9..cf628c9d 100644 --- a/example/examples/echo-dialer.rs +++ b/example/examples/echo-dialer.rs @@ -88,7 +88,11 @@ fn main() { // We use it to dial the address. let dialer = transport .dial_and_listen(swarm::Multiaddr::new(&target_addr).expect("invalid multiaddr")) - .unwrap_or_else(|_| panic!("unsupported multiaddr protocol ; should never happen")) + // If the multiaddr protocol exists but is not supported, then we get an error containing + // the transport and the original multiaddress. Therefore we cannot directly use `unwrap()` + // or `expect()`, but have to add a `map_err()` beforehand. + .map_err(|(_, addr)| addr).expect("unsupported multiaddr") + .and_then(|(incoming, echo)| { // `echo` is what the closure used when initializing "echo" returns. // Consequently, please note that the `send` method is available only because the type diff --git a/example/examples/echo-server.rs b/example/examples/echo-server.rs index 43ffc77f..9f803e58 100644 --- a/example/examples/echo-server.rs +++ b/example/examples/echo-server.rs @@ -88,7 +88,10 @@ fn main() { // We use it to listen on the address. let (listener, address) = transport .listen_on(swarm::Multiaddr::new(&listen_addr).expect("invalid multiaddr")) - .unwrap_or_else(|_| panic!("unsupported multiaddr protocol ; should never happen")); + // If the multiaddr protocol exists but is not supported, then we get an error containing + // the transport and the original multiaddress. Therefore we cannot directly use `unwrap()` + // or `expect()`, but have to add a `map_err()` beforehand. + .map_err(|(_, addr)| addr).expect("unsupported multiaddr"); println!("Now listening on {:?}", address); let future = listener