Auto merge of #126877 - GrigorenkoPV:clone_to_uninit, r=dtolnay

CloneToUninit impls

As per #126799.

Also implements it for `Wtf8` and both versions of `os_str::Slice`.

Maybe it is worth to slap `#[inline]` on some of those impls.

r? `@dtolnay`
This commit is contained in:
bors
2024-08-17 11:39:08 +00:00
11 changed files with 290 additions and 105 deletions

View File

@@ -1,6 +1,9 @@
//! The underlying OsString/OsStr implementation on Unix and many other
//! systems: just a `Vec<u8>`/`[u8]`.
use core::clone::CloneToUninit;
use core::ptr::addr_of_mut;
use crate::borrow::Cow;
use crate::collections::TryReserveError;
use crate::fmt::Write;
@@ -345,3 +348,13 @@ impl Slice {
self.inner.eq_ignore_ascii_case(&other.inner)
}
}
#[unstable(feature = "clone_to_uninit", issue = "126799")]
unsafe impl CloneToUninit for Slice {
#[inline]
#[cfg_attr(debug_assertions, track_caller)]
unsafe fn clone_to_uninit(&self, dst: *mut Self) {
// SAFETY: we're just a wrapper around [u8]
unsafe { self.inner.clone_to_uninit(addr_of_mut!((*dst).inner)) }
}
}

View File

@@ -1,5 +1,8 @@
//! The underlying OsString/OsStr implementation on Windows is a
//! wrapper around the "WTF-8" encoding; see the `wtf8` module for more.
use core::clone::CloneToUninit;
use core::ptr::addr_of_mut;
use crate::borrow::Cow;
use crate::collections::TryReserveError;
use crate::rc::Rc;
@@ -268,3 +271,13 @@ impl Slice {
self.inner.eq_ignore_ascii_case(&other.inner)
}
}
#[unstable(feature = "clone_to_uninit", issue = "126799")]
unsafe impl CloneToUninit for Slice {
#[inline]
#[cfg_attr(debug_assertions, track_caller)]
unsafe fn clone_to_uninit(&self, dst: *mut Self) {
// SAFETY: we're just a wrapper around Wtf8
unsafe { self.inner.clone_to_uninit(addr_of_mut!((*dst).inner)) }
}
}