#[non_exhaustive]pub enum UniAddr<'a> {
Inet(SocketAddr),
Unix(UnixAddr<'a>),
Host(HostAddr<'a>),
}Expand description
A unified address type that can represent:
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Implementations§
Source§impl<'a> UniAddr<'a>
impl<'a> UniAddr<'a>
Sourcepub fn from_str(string: &'a str) -> Result<UniAddr<'a>, ParseError>
pub fn from_str(string: &'a str) -> Result<UniAddr<'a>, ParseError>
Creates a new UniAddr from the given string representation.
use uaddr::UniAddr;
// An IPv4 address with a port
let _ = UniAddr::from_str("127.0.0.1:13168").unwrap();
// An IPv6 address with a port
let _ = UniAddr::from_str("[::1]:13168").unwrap();
// A host with a port
let _ = UniAddr::from_str("example.com:8080").unwrap();
// A UDS address (UNIX domain socket)
let _ = UniAddr::from_str("unix:/path/to/your/file.socket").unwrap();
// A URI-style UDS address (not recommended)
let _ = UniAddr::from_str("unix:///path/to/your/file.socket").unwrap();
// An abstract namespace UDS address.
let _ = UniAddr::from_str("unix:@abstract-socket").unwrap();
// A URI-style abstract namespace UDS address (not recommended).
let _ = UniAddr::from_str("unix://@abstract-socket").unwrap();Sourcepub const fn resolved(&self) -> Result<SocketAddr, InvalidUniAddr>
pub const fn resolved(&self) -> Result<SocketAddr, InvalidUniAddr>
Returns the resolved socket address if this is an SocketAddr or a
resolved HostAddr.
use uaddr::UniAddr;
// An already resolved IP address with a port can be resolved to a socket address.
let mut addr = UniAddr::from_str("1.1.1.1:443").unwrap();
assert!(addr
.resolved()
.is_ok_and(|addr| addr == "1.1.1.1:443".parse().unwrap()));
// An unresolved host address cannot be resolved to a socket address.
let mut addr = UniAddr::from_str("example.com:8080").unwrap();
assert!(addr.resolved().is_err());
// One UNIX domain socket address cannot be resolved to a socket address.
let mut addr = UniAddr::from_str("unix:/path/to/your/file.socket").unwrap();
assert!(addr.resolved().is_err());Sourcepub fn blocking_resolve_host_name(&mut self) -> Result<(), Error>
pub fn blocking_resolve_host_name(&mut self) -> Result<(), Error>
Sourcepub fn blocking_resolve_host_name_with<F, E>(&mut self, f: F) -> Result<(), E>
pub fn blocking_resolve_host_name_with<F, E>(&mut self, f: F) -> Result<(), E>
Sourcepub async fn resolve_host_name_with<'fut, F, Fut, E>(
&'fut mut self,
f: F,
) -> Result<(), E>
pub async fn resolve_host_name_with<'fut, F, Fut, E>( &'fut mut self, f: F, ) -> Result<(), E>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for UniAddr<'de>
impl<'de> Deserialize<'de> for UniAddr<'de>
Source§fn deserialize<D>(
deserializer: D,
) -> Result<UniAddr<'de>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<UniAddr<'de>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<&SocketAddr> for UniAddr<'_>
impl From<&SocketAddr> for UniAddr<'_>
Source§fn from(addr: &SocketAddr) -> UniAddr<'_>
fn from(addr: &SocketAddr) -> UniAddr<'_>
Converts to this type from the input type.
Source§impl From<SocketAddr> for UniAddr<'_>
impl From<SocketAddr> for UniAddr<'_>
Source§fn from(addr: SocketAddr) -> UniAddr<'_>
fn from(addr: SocketAddr) -> UniAddr<'_>
Converts to this type from the input type.
Source§impl Serialize for UniAddr<'_>
impl Serialize for UniAddr<'_>
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
Source§impl<'a> TryFrom<&'a SocketAddr> for UniAddr<'a>
impl<'a> TryFrom<&'a SocketAddr> for UniAddr<'a>
Source§type Error = ParseError
type Error = ParseError
The type returned in the event of a conversion error.
Source§fn try_from(
value: &'a SocketAddr,
) -> Result<UniAddr<'a>, <UniAddr<'a> as TryFrom<&'a SocketAddr>>::Error>
fn try_from( value: &'a SocketAddr, ) -> Result<UniAddr<'a>, <UniAddr<'a> as TryFrom<&'a SocketAddr>>::Error>
Performs the conversion.
Source§impl TryFrom<SocketAddr> for UniAddr<'static>
impl TryFrom<SocketAddr> for UniAddr<'static>
Source§type Error = ParseError
type Error = ParseError
The type returned in the event of a conversion error.
Source§fn try_from(
value: SocketAddr,
) -> Result<UniAddr<'static>, <UniAddr<'static> as TryFrom<SocketAddr>>::Error>
fn try_from( value: SocketAddr, ) -> Result<UniAddr<'static>, <UniAddr<'static> as TryFrom<SocketAddr>>::Error>
Performs the conversion.
impl<'a> Eq for UniAddr<'a>
impl<'a> StructuralPartialEq for UniAddr<'a>
Auto Trait Implementations§
impl<'a> Freeze for UniAddr<'a>
impl<'a> RefUnwindSafe for UniAddr<'a>
impl<'a> Send for UniAddr<'a>
impl<'a> Sync for UniAddr<'a>
impl<'a> Unpin for UniAddr<'a>
impl<'a> UnsafeUnpin for UniAddr<'a>
impl<'a> UnwindSafe for UniAddr<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more