Skip to main content

UniAddr

Enum UniAddr 

Source
#[non_exhaustive]
pub enum UniAddr<'a> { Inet(SocketAddr), Unix(UnixAddr<'a>), Host(HostAddr<'a>), }
Expand description

A unified address type that can represent:

Currently, the lifetime parameter 'a is not actually used. See UnixAddr or HostAddr for more details.

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>

Source

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();
Source

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());
Source

pub fn blocking_resolve_host_name(&mut self) -> Result<(), Error>

Source

pub fn blocking_resolve_host_name_with<F, E>(&mut self, f: F) -> Result<(), E>
where F: FnOnce(&str) -> Result<SocketAddr, E>,

Source

pub async fn resolve_host_name_with<'fut, F, Fut, E>( &'fut mut self, f: F, ) -> Result<(), E>
where F: FnOnce(&'fut str) -> Fut + Send, Fut: Future<Output = Result<SocketAddr, E>> + Send + 'fut,

Source

pub fn to_owned(self) -> UniAddr<'static>

Converts this UniAddr into an owned version.

This is a no-op for now since the inner bytes type is already owned, but it will be useful in the future when we change the inner bytes type to a more flexible one and accept borrowed bytes.

Trait Implementations§

Source§

impl<'a> Clone for UniAddr<'a>

Source§

fn clone(&self) -> UniAddr<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for UniAddr<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

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>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for UniAddr<'_>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&HostAddr<'a>> for UniAddr<'a>

Source§

fn from(addr: &HostAddr<'a>) -> UniAddr<'a>

Converts to this type from the input type.
Source§

impl From<&SocketAddr> for UniAddr<'_>

Source§

fn from(addr: &SocketAddr) -> UniAddr<'_>

Converts to this type from the input type.
Source§

impl<'a> From<&UnixAddr<'a>> for UniAddr<'a>

Source§

fn from(addr: &UnixAddr<'a>) -> UniAddr<'a>

Converts to this type from the input type.
Source§

impl<'a> From<HostAddr<'a>> for UniAddr<'a>

Source§

fn from(addr: HostAddr<'a>) -> UniAddr<'a>

Converts to this type from the input type.
Source§

impl From<SocketAddr> for UniAddr<'_>

Source§

fn from(addr: SocketAddr) -> UniAddr<'_>

Converts to this type from the input type.
Source§

impl<'a> From<UnixAddr<'a>> for UniAddr<'a>

Source§

fn from(addr: UnixAddr<'a>) -> UniAddr<'a>

Converts to this type from the input type.
Source§

impl FromStr for UniAddr<'static>

Source§

fn from_str( s: &str, ) -> Result<UniAddr<'static>, <UniAddr<'static> as FromStr>::Err>

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

impl<'a> Hash for UniAddr<'a>

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a> PartialEq for UniAddr<'a>

Source§

fn eq(&self, other: &UniAddr<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for UniAddr<'_>

Source§

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>

Source§

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>

Performs the conversion.
Source§

impl TryFrom<SocketAddr> for UniAddr<'static>

Source§

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>

Performs the conversion.
Source§

impl<'a> Eq for UniAddr<'a>

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.