From c0f833dcdcdc3459056281833e77bc33f028869c Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Thu, 25 Apr 2019 17:17:01 +0200 Subject: openpgp: Implement From> for UserID. --- openpgp/src/packet/userid.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'openpgp/src/packet/userid.rs') diff --git a/openpgp/src/packet/userid.rs b/openpgp/src/packet/userid.rs index 4a1ecec4..64f76b13 100644 --- a/openpgp/src/packet/userid.rs +++ b/openpgp/src/packet/userid.rs @@ -50,6 +50,15 @@ impl<'a> From<&'a str> for UserID { } } +impl<'a> From<::std::borrow::Cow<'a, str>> for UserID { + fn from(u: ::std::borrow::Cow<'a, str>) -> Self { + let b = u.as_bytes(); + let mut v = Vec::with_capacity(b.len()); + v.extend_from_slice(b); + v.into() + } +} + impl fmt::Display for UserID { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let userid = String::from_utf8_lossy(&self.value[..]); -- cgit v1.2.3