Skip to content
This repository was archived by the owner on Oct 23, 2022. It is now read-only.

Commit 3d677c6

Browse files
committed
fix(http): use slice pattern matching for MultiAddr match/conversion to SocketAddr
1 parent 9fb93fc commit 3d677c6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

http/src/main.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ fn serve<Types: IpfsTypes>(
192192
ipfs: &Ipfs<Types>,
193193
listening_addr: Multiaddr,
194194
) -> (std::net::SocketAddr, impl std::future::Future<Output = ()>) {
195+
use std::net::SocketAddr;
195196
use tokio::stream::StreamExt;
196197
use warp::Filter;
197198

@@ -204,13 +205,13 @@ fn serve<Types: IpfsTypes>(
204205

205206
let components = listening_addr.iter().collect::<Vec<_>>();
206207

207-
use std::net::SocketAddr;
208-
let socket_addr =
209-
if let (Protocol::Ip4(ip), Protocol::Tcp(port)) = (&components[0], &components[1]) {
210-
SocketAddr::new(ip.clone().into(), *port)
211-
} else {
212-
panic!("Couldn't convert MultiAddr into SocketAddr")
213-
};
208+
let socket_addr = match components.as_slice() {
209+
[Protocol::Ip4(ip), Protocol::Tcp(port)] => SocketAddr::new(ip.clone().into(), *port),
210+
_ => panic!(
211+
"Couldn't convert MultiAddr into SocketAddr: {}",
212+
listening_addr
213+
),
214+
};
214215

215216
warp::serve(routes).bind_with_graceful_shutdown(socket_addr, async move {
216217
shutdown_rx.next().await;

0 commit comments

Comments
 (0)