Skip to content

Commit 8b7191b

Browse files
committed
Add From<Cow<str>> for CowRcStr
1 parent 32733fb commit 8b7191b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/compact_cow_str.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
use std::borrow::Borrow;
5+
use std::borrow::{Borrow, Cow};
66
use std::cmp;
77
use std::fmt;
88
use std::hash;
@@ -42,6 +42,16 @@ fn _static_assert_same_size<'a>() {
4242
let _ = mem::transmute::<CowRcStr<'a>, Option<CowRcStr<'a>>>;
4343
}
4444

45+
impl<'a> From<Cow<'a, str>> for CowRcStr<'a> {
46+
#[inline]
47+
fn from(s: Cow<'a, str>) -> Self {
48+
match s {
49+
Cow::Borrowed(s) => CowRcStr::from(s),
50+
Cow::Owned(s) => CowRcStr::from(s),
51+
}
52+
}
53+
}
54+
4555
impl<'a> From<&'a str> for CowRcStr<'a> {
4656
#[inline]
4757
fn from(s: &'a str) -> Self {

0 commit comments

Comments
 (0)