Skip to content

Commit

Permalink
Added a new method to extra::future (unwrap) + a test
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiez authored and thestinger committed Jul 20, 2013
1 parent ddd8c15 commit eb74f0c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/libextra/future.rs
Expand Up @@ -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> {
pub fn get_ref<'a>(&'a mut self) -> &'a A {
/*!
Expand Down Expand Up @@ -179,6 +192,12 @@ mod test {
assert_eq!(f.get(), ~"fail");
}

#[test]
fn test_interface_unwrap() {
let mut f = from_value(~"fail");
assert_eq!(f.unwrap(), ~"fail");
}

#[test]
fn test_get_ref_method() {
let mut f = from_value(22);
Expand Down

0 comments on commit eb74f0c

Please sign in to comment.