Enum ServerName

#[non_exhaustive]
pub enum ServerName<'a>

Encodes ways a client can know the expected name of the server.

This currently covers knowing the DNS name of the server, but will be extended in the future to supporting privacy-preserving names for the server ("ECH"). For this reason this enum is non_exhaustive.

Making one

If you have a DNS name as a &str, this type implements TryFrom<&str>, so you can do:

# use rustls_pki_types::ServerName;
ServerName::try_from("example.com").expect("invalid DNS name");

If you have an owned String, you can use TryFrom directly:

# use rustls_pki_types::ServerName;
let name = "example.com".to_string();
#[cfg(feature = "alloc")]
ServerName::try_from(name).expect("invalid DNS name");

which will yield a ServerName<'static> if successful.

or, alternatively...

# use rustls_pki_types::ServerName;
let x: ServerName = "example.com".try_into().expect("invalid DNS name");

Variants

DnsName(DnsName<'a>)

The server is identified by a DNS name. The name is sent in the TLS Server Name Indication (SNI) extension.

IpAddress(IpAddr)

The server is identified by an IP address. SNI is not done.

Implementations

impl ServerName<'_>

fn to_owned(&self) -> ServerName<'static>

Produce an owned ServerName from this (potentially borrowed) ServerName.

fn to_str(&self) -> Cow<'_, str>

Return the string representation of this ServerName.

In the case of a ServerName::DnsName instance, this function returns a borrowed str. For a ServerName::IpAddress instance it returns an allocated String.

Trait Implementations

impl Debug for ServerName<'_>

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

impl From<IpAddr> for ServerName<'_>

fn from(addr: IpAddr) -> Self

impl From<IpAddr> for ServerName<'_>

fn from(addr: IpAddr) -> Self

impl From<Ipv4Addr> for ServerName<'_>

fn from(v4: Ipv4Addr) -> Self

impl From<Ipv4Addr> for ServerName<'_>

fn from(v4: Ipv4Addr) -> Self

impl From<Ipv6Addr> for ServerName<'_>

fn from(v6: Ipv6Addr) -> Self

impl From<Ipv6Addr> for ServerName<'_>

fn from(v6: Ipv6Addr) -> Self

impl TryFrom<String> for ServerName<'static>

type Error = InvalidDnsNameError;
fn try_from(value: String) -> Result<Self, Self::Error>

impl<'a> Clone for ServerName<'a>

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

impl<'a> Eq for ServerName<'a>

impl<'a> From<DnsName<'a>> for ServerName<'a>

fn from(dns_name: DnsName<'a>) -> Self

impl<'a> Hash for ServerName<'a>

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

impl<'a> PartialEq for ServerName<'a>

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

impl<'a> StructuralPartialEq for ServerName<'a>

impl<'a> TryFrom<&'a [u8]> for ServerName<'a>

type Error = InvalidDnsNameError;
fn try_from(value: &'a [u8]) -> Result<Self, Self::Error>

impl<'a> TryFrom<&'a str> for ServerName<'a>

type Error = InvalidDnsNameError;
fn try_from(s: &'a str) -> Result<Self, Self::Error>

Auto Trait Implementations

impl<'a> Freeze for ServerName<'a>

impl<'a> RefUnwindSafe for ServerName<'a>

impl<'a> Send for ServerName<'a>

impl<'a> Sync for ServerName<'a>

impl<'a> Unpin for ServerName<'a>

impl<'a> UnsafeUnpin for ServerName<'a>

impl<'a> UnwindSafe for ServerName<'a>

Blanket Implementations

impl<T> Any for ServerName<'a> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for ServerName<'a> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for ServerName<'a> where T: ?Sized,

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

impl<T> CloneToUninit for ServerName<'a> where T: Clone,

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

impl<T> From<T> for ServerName<'a>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for ServerName<'a> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for ServerName<'a> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom<U> for ServerName<'a> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for ServerName<'a> where U: TryFrom<T>,

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