From eec096aab0bd4c1b1af2458e319e5c18bd9f739a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Bene=C5=A1?= Date: Thu, 25 Jul 2024 15:07:02 +0200 Subject: [PATCH] `impl<'a> From<&'a BString> for Cow<'a, BStr>` This commit simplifies code in situations like: ``` let mut v = Vec::>::new(); let s = BString::new(...); // Before this commit, we would have to do: // v.push(s.as_bstr().into()); v.push(s.into()); ``` --- src/impls.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/impls.rs b/src/impls.rs index b6c68d0..17241e2 100644 --- a/src/impls.rs +++ b/src/impls.rs @@ -268,6 +268,13 @@ mod bstring { } } + impl<'a> From<&'a BString> for Cow<'a, BStr> { + #[inline] + fn from(s: &'a BString) -> Cow<'a, BStr> { + Cow::Borrowed(s.as_bstr()) + } + } + impl TryFrom for String { type Error = crate::FromUtf8Error;