diff options
| author | Eduardo Sánchez Muñoz <eduardosm-dev@e64.io> | 2024-10-22 21:14:22 +0200 |
|---|---|---|
| committer | Eduardo Sánchez Muñoz <eduardosm-dev@e64.io> | 2024-10-29 21:24:12 +0100 |
| commit | 9fe9041cc8eddaed402d17aa4facb2ce8f222e95 (patch) | |
| tree | 2c5f1588efbefffd043e3e4e9c3d731962b5a806 /library/alloc/src/ffi | |
| parent | 2dece5bb62f234f5622a08289c5a3d1555cd7843 (diff) | |
| download | rust-9fe9041cc8eddaed402d17aa4facb2ce8f222e95.tar.gz rust-9fe9041cc8eddaed402d17aa4facb2ce8f222e95.zip | |
Implement `From<&mut {slice}>` for `Box/Rc/Arc<{slice}>`
Diffstat (limited to 'library/alloc/src/ffi')
| -rw-r--r-- | library/alloc/src/ffi/c_str.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/library/alloc/src/ffi/c_str.rs b/library/alloc/src/ffi/c_str.rs index d7e99f4a1a6..d91682b796e 100644 --- a/library/alloc/src/ffi/c_str.rs +++ b/library/alloc/src/ffi/c_str.rs @@ -772,6 +772,16 @@ impl From<&CStr> for Box<CStr> { } } +#[cfg(not(test))] +#[stable(feature = "box_from_mut_slice", since = "CURRENT_RUSTC_VERSION")] +impl From<&mut CStr> for Box<CStr> { + /// Converts a `&mut CStr` into a `Box<CStr>`, + /// by copying the contents into a newly allocated [`Box`]. + fn from(s: &mut CStr) -> Box<CStr> { + Self::from(&*s) + } +} + #[stable(feature = "box_from_cow", since = "1.45.0")] impl From<Cow<'_, CStr>> for Box<CStr> { /// Converts a `Cow<'a, CStr>` into a `Box<CStr>`, @@ -910,6 +920,17 @@ impl From<&CStr> for Arc<CStr> { } } +#[cfg(target_has_atomic = "ptr")] +#[stable(feature = "shared_from_mut_slice", since = "CURRENT_RUSTC_VERSION")] +impl From<&mut CStr> for Arc<CStr> { + /// Converts a `&mut CStr` into a `Arc<CStr>`, + /// by copying the contents into a newly allocated [`Arc`]. + #[inline] + fn from(s: &mut CStr) -> Arc<CStr> { + Arc::from(&*s) + } +} + #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From<CString> for Rc<CStr> { /// Converts a [`CString`] into an <code>[Rc]<[CStr]></code> by moving the [`CString`] @@ -932,6 +953,16 @@ impl From<&CStr> for Rc<CStr> { } } +#[stable(feature = "shared_from_mut_slice", since = "CURRENT_RUSTC_VERSION")] +impl From<&mut CStr> for Rc<CStr> { + /// Converts a `&mut CStr` into a `Rc<CStr>`, + /// by copying the contents into a newly allocated [`Rc`]. + #[inline] + fn from(s: &mut CStr) -> Rc<CStr> { + Rc::from(&*s) + } +} + #[cfg(not(no_global_oom_handling))] #[stable(feature = "more_rc_default_impls", since = "1.80.0")] impl Default for Rc<CStr> { |
