1
Fork 0

impl From<Cow> for boxed slices and strings

These forward `Borrowed`/`Owned` values to existing `Box::from` impls.

- `From<Cow<'_, [T]>> for Box<[T]>`
- `From<Cow<'_, str>> for Box<str>`
- `From<Cow<'_, CStr>> for Box<CStr>`
- `From<Cow<'_, OsStr>> for Box<OsStr>`
- `From<Cow<'_, Path>> for Box<Path>`
This commit is contained in:
Josh Stone 2020-04-22 13:03:05 -07:00
parent 82e90d6426
commit b0fb57bd8d
4 changed files with 56 additions and 0 deletions

View file

@ -1433,6 +1433,17 @@ impl From<&Path> for Box<Path> {
}
}
#[stable(feature = "box_from_cow", since = "1.45.0")]
impl From<Cow<'_, Path>> for Box<Path> {
#[inline]
fn from(cow: Cow<'_, Path>) -> Box<Path> {
match cow {
Cow::Borrowed(path) => Box::from(path),
Cow::Owned(path) => Box::from(path),
}
}
}
#[stable(feature = "path_buf_from_box", since = "1.18.0")]
impl From<Box<Path>> for PathBuf {
/// Converts a `Box<Path>` into a `PathBuf`