diff --git a/src/libcore/result.rs b/src/libcore/result.rs index a3a889d94da..a8aa250ddad 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -216,6 +216,21 @@ fn iter2(ss: [S], ts: [T], ret ok(()); } +#[doc=" +Unwraps a result, assuming it is an `ok(T)` + +This operation is unsafe. +"] +fn unwrap(-res: result) -> 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; +} + #[cfg(test)] mod tests { fn op1() -> result::result { result::ok(666) }