Open
Description
The needed API just hit nightly: <*mut T>::set_ptr_value(self, *mut u8) -> *mut T
The problematic section:
Lines 109 to 113 in 754c7c7
As implemented, this relies on the fact that the layout of fat pointers puts the data pointer first and the fat part second. This is currently true, and the way that the compiler/stdlib implement this functionality, but could potentially change in the future. Whatever form set_ptr_value
ends up stabilizing in will be the sound way to accomplish this.
pub fn clone_box<T>(t: &T) -> Box<T>
where
T: ?Sized + DynClone,
{
let raw_clone = (t as *const T).set_ptr_value(<T as DynClone>::clone_box(t) as *const u8);
unsafe {
Box::from_raw(raw_clone as *mut T)
}
}
(Since DynClone::clone_box
is a private non-public API, it'll probably want to change its signature to match whatever the argument for set_ptr_value
settles on.)
Metadata
Metadata
Assignees
Labels
No labels