dairy/
to_boxed.rs

1#![allow(clippy::wrong_self_convention)]
2
3use alloc::borrow::ToOwned;
4use alloc::boxed::Box;
5
6/// Converts the owned version of self into boxed data.
7///
8/// This trait should not be used directly but instead through the
9/// [`.into_boxed()`][crate::Cow::into_boxed] method on [`Cow`][crate::Cow].
10pub trait ToBoxed: ToOwned {
11    fn to_boxed(o: Self::Owned) -> Box<Self>;
12}
13
14impl ToBoxed for str {
15    #[inline]
16    fn to_boxed(o: Self::Owned) -> Box<Self> {
17        o.into_boxed_str()
18    }
19}
20
21impl<T: Clone> ToBoxed for [T] {
22    #[inline]
23    fn to_boxed(o: Self::Owned) -> Box<Self> {
24        o.into_boxed_slice()
25    }
26}
27
28#[cfg(feature = "std")]
29impl ToBoxed for std::ffi::CStr {
30    #[inline]
31    fn to_boxed(o: Self::Owned) -> Box<Self> {
32        o.into_boxed_c_str()
33    }
34}
35
36#[cfg(feature = "std")]
37impl ToBoxed for std::ffi::OsStr {
38    #[inline]
39    fn to_boxed(o: Self::Owned) -> Box<Self> {
40        o.into_boxed_os_str()
41    }
42}
43
44#[cfg(feature = "std")]
45impl ToBoxed for std::path::Path {
46    #[inline]
47    fn to_boxed(o: Self::Owned) -> Box<Self> {
48        o.into_boxed_path()
49    }
50}