Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. use std::boxed::Box;
  2. use libc::c_void;
  3.  
  4. fn main() {
  5. show_ptr(get_ptr());
  6. }
  7.  
  8. fn get_ptr() -> (*mut c_void, *mut c_void) {
  9. let x = vec!["Hello".to_string(), "World".to_string()].into_boxed_slice();
  10. let ptr = Box::into_raw(x);
  11. unsafe { std::mem::transmute::<_, (*mut c_void, *mut c_void)>(ptr) }
  12. }
  13.  
  14. fn show_ptr(ptr: (*mut c_void, *mut c_void)) {
  15. let x = unsafe { Box::from_raw(std::mem::transmute::<_, *mut [String]>(ptr)) };
  16. println!("{:?}", x);
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement