Added a new method to extra::future (unwrap) + a test
This commit is contained in:
committed by
Daniel Micay
parent
ddd8c156c6
commit
eb74f0ccf6
@@ -60,6 +60,19 @@ impl<A:Clone> Future<A> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<A> Future<A> {
|
||||||
|
/// Gets the value from this future, forcing evaluation.
|
||||||
|
pub fn unwrap(self) -> A {
|
||||||
|
let mut this = self;
|
||||||
|
this.get_ref();
|
||||||
|
let state = replace(&mut this.state, Evaluating);
|
||||||
|
match state {
|
||||||
|
Forced(v) => v,
|
||||||
|
_ => fail!( "Logic error." ),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<A> Future<A> {
|
impl<A> Future<A> {
|
||||||
pub fn get_ref<'a>(&'a mut self) -> &'a A {
|
pub fn get_ref<'a>(&'a mut self) -> &'a A {
|
||||||
/*!
|
/*!
|
||||||
@@ -179,6 +192,12 @@ mod test {
|
|||||||
assert_eq!(f.get(), ~"fail");
|
assert_eq!(f.get(), ~"fail");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_interface_unwrap() {
|
||||||
|
let mut f = from_value(~"fail");
|
||||||
|
assert_eq!(f.unwrap(), ~"fail");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_ref_method() {
|
fn test_get_ref_method() {
|
||||||
let mut f = from_value(22);
|
let mut f = from_value(22);
|
||||||
|
|||||||
Reference in New Issue
Block a user