4 ms·
Like in C you can cast the pointer to an integer and back. Rust allows such hacks if you mark them with a "hold my beer" keyword: let the_bits:usize = unsa
by pornel 10y ago
Like in C you can cast the pointer to an integer and back. Rust allows such hacks if you mark them with a "hold my beer" keyword:
let the_bits:usize = unsafe { std::mem::transmute(pointer) };
You can also use `std::mem::forget(*pointer)` to avoid fighting with Rust about who manages the memory.
- FreeFull 10y agoYou can actually turn a pointer into an usize without using an unsafe block. For example, here's how you'd do it with a reference: let the_bits = pointer as *const _ as usize;