Skip to content

Instantly share code, notes, and snippets.

@stepancheg
Last active August 29, 2015 14:09
Show Gist options
  • Save stepancheg/218d34510917e2b4f63b to your computer and use it in GitHub Desktop.
Save stepancheg/218d34510917e2b4f63b to your computer and use it in GitHub Desktop.
#![feature(unsafe_destructor)]
#[deriving(Show)]
struct Uninit<T> {
pub value: T
}
impl<T> Uninit<T> {
unsafe fn new() -> Uninit<T> {
Uninit {
value: std::intrinsics::uninit()
}
}
}
#[unsafe_destructor]
impl<T> Drop for Uninit<T> {
fn drop(&mut self) {
// owner is responsible for drop
}
}
fn main() {
let mut v: Vec<Uninit<uint>> = Vec::new();
for _ in range(0u, 5) {
v.push(unsafe { Uninit::new() });
}
println!("{}", v);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment