miden_node_utils/
grpc.rs

1use std::net::SocketAddr;
2
3use anyhow::Context;
4
5/// A sealed extension trait for [`url::Url`] that adds convenience functions for binding and
6/// connecting to the url.
7pub trait UrlExt: private::Sealed {
8    fn to_socket(&self) -> anyhow::Result<SocketAddr>;
9}
10
11impl UrlExt for url::Url {
12    fn to_socket(&self) -> anyhow::Result<SocketAddr> {
13        self.socket_addrs(|| None)?
14            .into_iter()
15            .next()
16            .with_context(|| format!("failed to convert url {self} to socket address"))
17    }
18}
19
20mod private {
21    pub trait Sealed {}
22    impl Sealed for url::Url {}
23}