miden_node_utils/
grpc.rs

1use std::net::SocketAddr;
2
3use crate::errors::ApiError;
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) -> Result<SocketAddr, ApiError>;
9}
10
11impl UrlExt for url::Url {
12    fn to_socket(&self) -> Result<SocketAddr, ApiError> {
13        self.socket_addrs(|| None)
14            .map_err(ApiError::EndpointToSocketFailed)?
15            .into_iter()
16            .next()
17            .ok_or_else(|| ApiError::AddressResolutionFailed(self.to_string()))
18    }
19}
20
21mod private {
22    pub trait Sealed {}
23    impl Sealed for url::Url {}
24}