@@ -31,7 +31,7 @@ pub enum GeneralDnsNameRef<'name> {
31
31
impl < ' a > From < GeneralDnsNameRef < ' a > > for & ' a str {
32
32
fn from ( d : GeneralDnsNameRef < ' a > ) -> Self {
33
33
match d {
34
- GeneralDnsNameRef :: DnsName ( name) => name. into ( ) ,
34
+ GeneralDnsNameRef :: DnsName ( name) => name. as_str ( ) ,
35
35
GeneralDnsNameRef :: Wildcard ( name) => name. into ( ) ,
36
36
}
37
37
}
@@ -82,15 +82,6 @@ impl AsRef<str> for DnsName {
82
82
#[ derive( Clone , Copy , Eq , PartialEq , Hash ) ]
83
83
pub struct DnsNameRef < ' a > ( pub ( crate ) & ' a [ u8 ] ) ;
84
84
85
- impl AsRef < str > for DnsNameRef < ' _ > {
86
- #[ inline]
87
- fn as_ref ( & self ) -> & str {
88
- // The unwrap won't fail because DnsNameRef are guaranteed to be ASCII
89
- // and ASCII is a subset of UTF-8.
90
- core:: str:: from_utf8 ( self . 0 ) . unwrap ( )
91
- }
92
- }
93
-
94
85
impl < ' a > DnsNameRef < ' a > {
95
86
/// Constructs a `DnsNameRef` from the given input if the input is a
96
87
/// syntactically-valid DNS name.
@@ -115,10 +106,15 @@ impl<'a> DnsNameRef<'a> {
115
106
/// Constructs a `DnsName` from this `DnsNameRef`
116
107
#[ cfg( feature = "alloc" ) ]
117
108
pub fn to_owned ( & self ) -> DnsName {
118
- // DnsNameRef is already guaranteed to be valid ASCII, which is a
119
- // subset of UTF-8.
120
- let s: & str = ( * self ) . into ( ) ;
121
- DnsName ( s. to_ascii_lowercase ( ) )
109
+ // DnsNameRef is already guaranteed to be valid ASCII, which is subset of UTF-8.
110
+ DnsName ( self . as_str ( ) . to_ascii_lowercase ( ) )
111
+ }
112
+
113
+ /// Yields a reference to the DNS name as a `&str`.
114
+ pub fn as_str ( & self ) -> & ' a str {
115
+ // The unwrap won't fail because `DnsNameRef` values are guaranteed to be ASCII and ASCII
116
+ // is a subset of UTF-8.
117
+ core:: str:: from_utf8 ( self . 0 ) . unwrap ( )
122
118
}
123
119
}
124
120
@@ -137,14 +133,6 @@ impl core::fmt::Debug for DnsNameRef<'_> {
137
133
}
138
134
}
139
135
140
- impl < ' a > From < DnsNameRef < ' a > > for & ' a str {
141
- fn from ( DnsNameRef ( d) : DnsNameRef < ' a > ) -> Self {
142
- // The unwrap won't fail because DnsNameRefs are guaranteed to be ASCII
143
- // and ASCII is a subset of UTF-8.
144
- core:: str:: from_utf8 ( d) . unwrap ( )
145
- }
146
- }
147
-
148
136
/// A reference to a DNS Name presented by a server that may include a wildcard.
149
137
///
150
138
/// A `WildcardDnsNameRef` is guaranteed to be syntactically valid. The validity rules
0 commit comments