跳到主要内容

ServerName

搜索

枚举 ServerName 

Source
#[non_exhaustive]
pub enum ServerName<'a> { DnsName(DnsName<'a>), IpAddress(IpAddr), }
展开描述

表示客户端获知服务器预期名称的途径。

当前它涵盖知晓服务器的 DNS 名称这一情形,未来将扩展到支持服务器的隐私保护名称(“ECH”)。 因此该枚举被声明为 non_exhaustive

§Making one

如果你拥有一个 &str 形式的 DNS 名称,该类型实现了 TryFrom<&str>, 因此你可以这样使用:

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

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

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…

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

变体 (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.
§

DnsName(DnsName<'a>)

服务器通过 DNS 名称标识。该名称通过 TLS 的 Server Name Indication (SNI) extension(服务器名称指示扩展)发送。

§

IpAddress(IpAddr)

服务器通过 IP 地址标识,不发送 SNI。

实现§

Source§

impl ServerName<'_>

Source

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

从一个(可能为借用的)ServerName 产生一个 owned 的 ServerName

Source

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

返回该 ServerName 的字符串表示形式。

对于 ServerName::DnsName 实例,此函数返回一个借用的 str。 对于 ServerName::IpAddress 实例,它返回一个分配而来的 String

trait 实现§

Source§

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

Source§

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

返回该值的一个副本。更多信息
1.0.0 · Source§

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

Performs copy-assignment from source. 更多信息
Source§

impl Debug for ServerName<'_>

Source§

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

使用给定的格式化器格式化该值。更多信息
Source§

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

Source§

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

将该输入类型转换为此类型。
Source§

impl From<IpAddr> for ServerName<'_>

Source§

fn from(addr: IpAddr) -> Self

将该输入类型转换为此类型。
Source§

impl From<IpAddr> for ServerName<'_>

Available on crate feature std only.
Source§

fn from(addr: IpAddr) -> Self

将该输入类型转换为此类型。
Source§

impl From<Ipv4Addr> for ServerName<'_>

Source§

fn from(v4: Ipv4Addr) -> Self

将该输入类型转换为此类型。
Source§

impl From<Ipv4Addr> for ServerName<'_>

Available on crate feature std only.
Source§

fn from(v4: Ipv4Addr) -> Self

将该输入类型转换为此类型。
Source§

impl From<Ipv6Addr> for ServerName<'_>

Source§

fn from(v6: Ipv6Addr) -> Self

将该输入类型转换为此类型。
Source§

impl From<Ipv6Addr> for ServerName<'_>

Available on crate feature std only.
Source§

fn from(v6: Ipv6Addr) -> Self

将该输入类型转换为此类型。
Source§

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

Source§

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

将该值送入给定的 Hasher 中。更多信息
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. 更多信息
Source§

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

Source§

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

测试 selfother 值是否相等,供 == 使用。
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<'a> TryFrom<&'a [u8]> for ServerName<'a>

Source§

type Error = InvalidDnsNameError

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

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

执行转换。
Source§

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

尝试将一个字符串解析为 DNS 名称或 IP 地址以构造 ServerName

Source§

type Error = InvalidDnsNameError

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

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

执行转换。
Source§

impl TryFrom<String> for ServerName<'static>

Available on crate feature alloc only.
Source§

type Error = InvalidDnsNameError

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

fn try_from(value: String) -> Result<Self, Self::Error>

执行转换。
Source§

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

Source§

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

自动 trait 实现§

§

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 实现§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. 更多信息
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. 更多信息
Source§

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

Source§

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

Mutably borrows from an owned value. 更多信息
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. 更多信息
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

原样返回参数。

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

即此转换的实际行为取决于 From<T> for U 的实现。

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. 更多信息
Source§

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

Uses borrowed data to replace owned data, usually by cloning. 更多信息
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>

执行转换。
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>

执行转换。