Fix concerns

This commit is contained in:
Pierre Krieger 2017-12-18 15:55:49 +01:00
parent c9f55ceb97
commit ae0f787e03
2 changed files with 9 additions and 2 deletions

View File

@ -88,7 +88,11 @@ fn main() {
// We use it to dial the address. // We use it to dial the address.
let dialer = transport let dialer = transport
.dial_and_listen(swarm::Multiaddr::new(&target_addr).expect("invalid multiaddr")) .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)| { .and_then(|(incoming, echo)| {
// `echo` is what the closure used when initializing "echo" returns. // `echo` is what the closure used when initializing "echo" returns.
// Consequently, please note that the `send` method is available only because the type // Consequently, please note that the `send` method is available only because the type

View File

@ -88,7 +88,10 @@ fn main() {
// We use it to listen on the address. // We use it to listen on the address.
let (listener, address) = transport let (listener, address) = transport
.listen_on(swarm::Multiaddr::new(&listen_addr).expect("invalid multiaddr")) .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); println!("Now listening on {:?}", address);
let future = listener let future = listener