Skip to content

Commit

Permalink
api: add impl<'a> From<&'a BString> for Cow<'a, BStr>
Browse files Browse the repository at this point in the history
This commit simplifies code in situations like:

```
let mut v = Vec::<Cow<'a, BStr>>::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
  • Loading branch information
wbenny authored Jul 25, 2024
1 parent 4f41e0b commit 06b1f14
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BString> for String {
type Error = crate::FromUtf8Error;

Expand Down

0 comments on commit 06b1f14

Please sign in to comment.