pub unsafe trait IntoMutSliceLikePtr<T>{
// Required method
fn into_mut_slice_like_ptr(ptr: *mut Self) -> *mut T;
}
Expand description
Trait for reinterpreting a pointer to a given type as a compatible
SliceLike
pointer that uses the exact same backing memory.
§Safety
This trait is marked as unsafe due to the potential for data loss if
implemented incorrectly. It is used within this crate to determine which
slice conversions are valid for a given Allocation
without requiring
the allocated data to be modified in any way. The source and destination
types must use the same exact storage memory, and dropping the data stored
in the destination type must also perform any cleanup required by the
original source type.
Required Methods§
Sourcefn into_mut_slice_like_ptr(ptr: *mut Self) -> *mut T
fn into_mut_slice_like_ptr(ptr: *mut Self) -> *mut T
Reinterprets a mutable pointer of this type as a SliceLike
pointer.
§Examples
use scratchpad::IntoMutSliceLikePtr;
let mut value = 3.14159;
let value_ptr: *mut f64 = &mut value;
let slice_ptr = IntoMutSliceLikePtr::into_mut_slice_like_ptr(
value_ptr,
);
assert_eq!(unsafe { &*slice_ptr }, [3.14159]);
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.