Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Forget lifetimes, do this. It's a bug. It's in the safe code. You fix it in the safe code, because it misused unsafe code.

  let vec: Vec<i32> = vec![1, 2, 3, 4, 5];
  let ptr = vec.as_ptr();
  let len = vec.len();
  
  let slice_ref = unsafe {slice::from_raw_parts(ptr, len)};
  
  drop(vec);
  
  println!("{:?}", slice_ref);


Okay I ended up replying to this example over here: https://news.ycombinator.com/item?id=46051496




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: