Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 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() -> (usize, *mut c_void) {
  9. let x = vec!["Hello".to_string(), "World".to_string()].into_boxed_slice();
  10. (x.len(), Box::into_raw(x) as *mut c_void)
  11. }
  12.  
  13. fn show_ptr(ptr: (usize, *mut c_void)) {
  14. let x = unsafe { Vec::from_raw_parts(ptr.1 as *mut String, ptr.0, ptr.0).into_boxed_slice() };
  15. println!("{:?}", x);
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement