-
-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Raw pointer cast functions #202
Comments
I would not necessarily be opposed to these, but a few notes:
let too_long: *const [u32] = std::ptr::slice_from_raw_parts(std::ptr::null(), usize::MAX);
let what_error_should_this_return: Result<*const [u8], PodCastError> = try_cast_slice_ptr(too_long); |
Yeah, there's a lot more small design work than it might seem at first. Personally, for volatile access i have the |
If I may, I would suggest to leave slice pointer casts out for now, but add support for I'm doing this in some of my projects, and I'm basically copy-pasting |
Since Rust 1.75.0, with the stabilization of |
Would it make sense to include cast functions that handle raw pointers?
fn cast_ptr(a: *const A) -> *const B
fn cast_mut_ptr(a: *mut A) -> *mut B
fn cast_slice_ptr(a: *const [A]) -> *const [B]
fn cast_mut_slice_ptr(a: *mut [A]) -> *mut [B]
This would be useful when working with data that is unsafe to take references to (e.g. volatile IO memory).
The text was updated successfully, but these errors were encountered: