Skip to content

Commit

Permalink
server_name: demonstrate using ServerName::to_owned
Browse files Browse the repository at this point in the history
It seems to be a common source of confusion that it's possible to
construct an owned `ServerName` from an owned `String` using the
existing API and `ServerName::to_owned`. This commit adds an explicit
example demonstrating this capability to help make it more discoverable.
  • Loading branch information
cpu committed Dec 5, 2023
1 parent 7ceb2f3 commit 99f4a89
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/server_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ use std::error::Error as StdError;
/// let x = "example.com".try_into().expect("invalid DNS name");
/// # let _: ServerName = x;
/// ```
///
/// If you require an owned `ServerName` with a `'static` lifetime and have enabled the `alloc`
/// feature, use [`ServerName::to_owned`]:
///
/// ```
/// # use rustls_pki_types::ServerName;
/// let my_servername = "example.com".to_string();
/// ServerName::try_from(my_servername.as_str()).expect("invalid DNS name").to_owned();
/// ```
#[non_exhaustive]
#[derive(Clone, Eq, Hash, PartialEq)]
pub enum ServerName<'a> {
Expand Down

0 comments on commit 99f4a89

Please sign in to comment.