Skip to content

Commit eb74f0c

Browse files
Thiezthestinger
authored andcommitted
Added a new method to extra::future (unwrap) + a test
1 parent ddd8c15 commit eb74f0c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/libextra/future.rs

+19
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ impl<A:Clone> Future<A> {
6060
}
6161
}
6262

63+
impl<A> Future<A> {
64+
/// Gets the value from this future, forcing evaluation.
65+
pub fn unwrap(self) -> A {
66+
let mut this = self;
67+
this.get_ref();
68+
let state = replace(&mut this.state, Evaluating);
69+
match state {
70+
Forced(v) => v,
71+
_ => fail!( "Logic error." ),
72+
}
73+
}
74+
}
75+
6376
impl<A> Future<A> {
6477
pub fn get_ref<'a>(&'a mut self) -> &'a A {
6578
/*!
@@ -179,6 +192,12 @@ mod test {
179192
assert_eq!(f.get(), ~"fail");
180193
}
181194
195+
#[test]
196+
fn test_interface_unwrap() {
197+
let mut f = from_value(~"fail");
198+
assert_eq!(f.unwrap(), ~"fail");
199+
}
200+
182201
#[test]
183202
fn test_get_ref_method() {
184203
let mut f = from_value(22);

0 commit comments

Comments
 (0)