Crates.io | totally-sound-ptr-int-cast |
lib.rs | totally-sound-ptr-int-cast |
version | 0.1.1 |
source | src |
created_at | 2022-03-31 06:48:27.031985 |
updated_at | 2022-03-31 06:53:01.858966 |
description | do i _look_ like a memory model? |
homepage | |
repository | https://github.com/ben0x539/totally-sound-ptr-int-cast |
max_upload_size | |
id | 559503 |
size | 6,359 |
Okay, so, it looks like as
-casts between usize
and raw pointer types are
on the way out. People are talking about how those make provenance really
annoying which is bad for formalizing a memory model. In this hypothetical
future, it would be highly illegal to cast a pointer to an integer, maybe
roundtrip it through some OS or FFI API, cast it back to an integer, and then
dereference it.
It may be too late to avert that terrible fate. In this doomed timeline, it may become necessary to use this crate to perform totally sound ptr<->int casts.
let n = totally_sound_ptr_int_cast::ptr2int(
Bxo::into_raw(your_boxed_stuff.into_raw()));
and, at any later point within the same program execution,
let p = totally_sound_ptr_int_cast::int2ptr_mut(n);
unsafe { println!("{:?}", &*p); } // or whatever
you get your stuff back.