2022-07-18 09:38:26 -05:00
|
|
|
#![feature(ptr_metadata, layout_for_ptr)]
|
|
|
|
|
|
|
|
use std::{mem, ptr};
|
2022-06-05 11:25:46 -05:00
|
|
|
|
|
|
|
trait Foo {}
|
|
|
|
|
|
|
|
impl Foo for u32 {}
|
|
|
|
|
|
|
|
fn uwu(thin: *const (), meta: &'static ()) -> *const dyn Foo {
|
2022-07-18 09:38:26 -05:00
|
|
|
ptr::from_raw_parts(thin, unsafe { mem::transmute(meta) })
|
2022-06-05 11:25:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
unsafe {
|
|
|
|
let orig = 1_u32;
|
|
|
|
let x = &orig as &dyn Foo;
|
|
|
|
let (ptr, meta) = (x as *const dyn Foo).to_raw_parts();
|
2022-07-18 09:38:26 -05:00
|
|
|
let ptr = uwu(ptr, mem::transmute(meta));
|
2022-07-22 06:52:32 -05:00
|
|
|
let _size = mem::size_of_val_raw(ptr);
|
2022-06-05 11:25:46 -05:00
|
|
|
}
|
|
|
|
}
|