#[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。