From 06b1f14ccb43d67285ba7661a412b2fb9a2a711a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Bene=C5=A1?= Date: Thu, 25 Jul 2024 15:20:50 +0200 Subject: [PATCH] api: add `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()); ``` PR #187 --- 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;