impl CloneToUninit for Path and OsStr

This commit is contained in:
Pavel Grigorenko
2024-06-23 23:05:10 +03:00
parent ec921db289
commit afabc583f7
8 changed files with 95 additions and 0 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,12 @@ impl Slice {
self.inner.eq_ignore_ascii_case(&other.inner)
}
}
#[unstable(feature = "clone_to_uninit", issue = "126799")]
unsafe impl CloneToUninit for Slice {
#[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,12 @@ impl Slice {
self.inner.eq_ignore_ascii_case(&other.inner)
}
}
#[unstable(feature = "clone_to_uninit", issue = "126799")]
unsafe impl CloneToUninit for Slice {
#[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)) }
}
}