Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis
Created May 2, 2012 19:02
Show Gist options
  • Save nikomatsakis/2579281 to your computer and use it in GitHub Desktop.
Save nikomatsakis/2579281 to your computer and use it in GitHub Desktop.
fn unwrap<T, U>(-res: result<T, U>) -> T unsafe {
let addr = alt res {
ok(x) { ptr::addr_of(x) }
err(_) { fail "option none" }
};
let liberated_value = unsafe::reinterpret_cast(*addr);
unsafe::forget(res);
ret liberated_value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment