Skip to content

Commit a0fb1e4

Browse files
committed
x509-cert: add deprecated as_ref and From<DirectoryString> for String
1 parent 611057e commit a0fb1e4

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

x509-cert/src/ext/pkix/name/dirstr.rs

+21
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,25 @@ impl DirectoryString {
9898
Self::BmpString(s) => Cow::Owned(s.to_string()),
9999
}
100100
}
101+
102+
/// Returns `&str` for `PrintableString`, `TeletexString` and `Utf8String`
103+
///
104+
/// Warning: Returns `""` empty string for [`DirectoryString::BmpString`] variant
105+
#[deprecated(since = "0.3.0-pre.0", note = "use `DirectoryString::value` instead")]
106+
#[allow(clippy::should_implement_trait)]
107+
pub fn as_ref(&self) -> &str {
108+
match self {
109+
Self::PrintableString(s) => s.as_ref(),
110+
Self::TeletexString(s) => s.as_ref(),
111+
Self::Utf8String(s) => s.as_ref(),
112+
// BMPString is not str-compatible
113+
Self::BmpString(_s) => "",
114+
}
115+
}
116+
}
117+
118+
impl From<DirectoryString> for String {
119+
fn from(value: DirectoryString) -> Self {
120+
value.value().into_owned()
121+
}
101122
}

0 commit comments

Comments
 (0)