Skip to content

Commit

Permalink
subject_name: deprecate From<DnsNameRef> for DnsName.
Browse files Browse the repository at this point in the history
As mentioned in the comment we can't outright `#[deprecate]` this one
because it's a trait impl.

Instead, promote the deprecation note to the rustdoc comment, add a TODO
to remove it outright, and switch our own tests to call `to_owned()`
directly in preparation of an eventual removal.
  • Loading branch information
cpu committed Apr 20, 2023
1 parent 657e7cb commit 0380181
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/subject_name/dns_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ impl AsRef<str> for DnsName {
}

/// Requires the `alloc` feature.
// Deprecated
/// Deprecated.
#[cfg(feature = "alloc")]
impl From<DnsNameRef<'_>> for DnsName {
// TODO(XXX): Remove this trait impl in the next release. We can't mark it as
// hard deprecated as this isn't supported and produces a
// 'useless_deprecated' warning.
fn from(dns_name: DnsNameRef) -> Self {
dns_name.to_owned()
}
Expand Down
13 changes: 10 additions & 3 deletions tests/name_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ fn test_dns_name_traits() {
let a_ref = DnsNameRef::try_from_ascii(b"example.com").unwrap();

// `From<DnsNameRef>`
// TODO(XXX): Remove when deprecated From<DnsNameRef> for DnsName trait is removed.
let a: DnsName = DnsName::from(a_ref);

// `Clone`, `Debug`, `PartialEq`.
Expand All @@ -52,16 +53,22 @@ fn test_dns_name_traits() {
// PartialEq is case-insensitive
assert_eq!(
a,
DnsName::from(DnsNameRef::try_from_ascii(b"Example.Com").unwrap())
DnsNameRef::try_from_ascii(b"Example.Com")
.unwrap()
.to_owned()
);

// PartialEq isn't completely wrong.
assert_ne!(
a,
DnsName::from(DnsNameRef::try_from_ascii(b"fxample.com").unwrap())
DnsNameRef::try_from_ascii(b"fxample.com")
.unwrap()
.to_owned()
);
assert_ne!(
a,
DnsName::from(DnsNameRef::try_from_ascii(b"example.co").unwrap())
DnsNameRef::try_from_ascii(b"example.co")
.unwrap()
.to_owned()
);
}

0 comments on commit 0380181

Please sign in to comment.