Implement From<&mut {slice}> for Box/Rc/Arc<{slice}>

This commit is contained in:
Eduardo Sánchez Muñoz
2024-10-22 21:14:22 +02:00
parent 2dece5bb62
commit 9fe9041cc8
6 changed files with 211 additions and 0 deletions

View File

@@ -1762,6 +1762,16 @@ impl From<&Path> for Box<Path> {
}
}
#[stable(feature = "box_from_mut_slice", since = "CURRENT_RUSTC_VERSION")]
impl From<&mut Path> for Box<Path> {
/// Creates a boxed [`Path`] from a reference.
///
/// This will allocate and clone `path` to it.
fn from(path: &mut Path) -> Box<Path> {
Self::from(&*path)
}
}
#[stable(feature = "box_from_cow", since = "1.45.0")]
impl From<Cow<'_, Path>> for Box<Path> {
/// Creates a boxed [`Path`] from a clone-on-write pointer.
@@ -1990,6 +2000,15 @@ impl From<&Path> for Arc<Path> {
}
}
#[stable(feature = "shared_from_mut_slice", since = "CURRENT_RUSTC_VERSION")]
impl From<&mut Path> for Arc<Path> {
/// Converts a [`Path`] into an [`Arc`] by copying the [`Path`] data into a new [`Arc`] buffer.
#[inline]
fn from(s: &mut Path) -> Arc<Path> {
Arc::from(&*s)
}
}
#[stable(feature = "shared_from_slice2", since = "1.24.0")]
impl From<PathBuf> for Rc<Path> {
/// Converts a [`PathBuf`] into an <code>[Rc]<[Path]></code> by moving the [`PathBuf`] data into
@@ -2011,6 +2030,15 @@ impl From<&Path> for Rc<Path> {
}
}
#[stable(feature = "shared_from_mut_slice", since = "CURRENT_RUSTC_VERSION")]
impl From<&mut Path> for Rc<Path> {
/// Converts a [`Path`] into an [`Rc`] by copying the [`Path`] data into a new [`Rc`] buffer.
#[inline]
fn from(s: &mut Path) -> Rc<Path> {
Rc::from(&*s)
}
}
#[stable(feature = "rust1", since = "1.0.0")]
impl ToOwned for Path {
type Owned = PathBuf;