Closed
Description
#60601 adds:
impl<T: ?Sized> *mut T {
/// Cast to a pointer to a different type
#[inline]
pub const fn cast<U>(self) -> *mut U {
self as _
}
}
impl<T: ?Sized> *const T {
/// Cast to a pointer to a different type
#[inline]
pub const fn cast<U>(self) -> *const U {
self as _
}
}
Like with NonNull::cast
, the input pointed type does not need to be Sized
but the output pointed type does, because we wouldn’t know what appropriate pointer metadata (slice length, trait object vtable, …) to insert. The actual requirement is that the pointer is thin, but Sized
is the closest approximation we have (until we add something like T: ptr::Pointee<Metadata=()>
).
Metadata
Metadata
Assignees
Labels
Blocker: Implemented in the nightly compiler and unstable.Category: An issue tracking the progress of sth. like the implementation of an RFCRelevant to the library API team, which will review and decide on the PR/issue.This issue / PR is in PFCP or FCP with a disposition to merge it.The final comment period is finished for this PR / Issue.