libstd: changes to in response to #5656
This commit is contained in:
@@ -55,7 +55,7 @@ pub impl<A:Copy> Future<A> {
|
||||
}
|
||||
|
||||
pub impl<A> Future<A> {
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn get_ref(&self) -> &'self A {
|
||||
/*!
|
||||
* Executes the future's closure and then returns a borrowed
|
||||
@@ -80,6 +80,34 @@ pub impl<A> Future<A> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn get_ref<'a>(&'a self) -> &'a A {
|
||||
/*!
|
||||
* Executes the future's closure and then returns a borrowed
|
||||
* pointer to the result. The borrowed pointer lasts as long as
|
||||
* the future.
|
||||
*/
|
||||
unsafe {
|
||||
match self.state {
|
||||
Forced(ref mut v) => { return cast::transmute(v); }
|
||||
Evaluating => fail!(~"Recursive forcing of future!"),
|
||||
Pending(_) => {}
|
||||
}
|
||||
|
||||
let mut state = Evaluating;
|
||||
self.state <-> state;
|
||||
match state {
|
||||
Forced(_) | Evaluating => fail!(~"Logic error."),
|
||||
Pending(f) => {
|
||||
self.state = Forced(f());
|
||||
self.get_ref()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_value<A>(val: A) -> Future<A> {
|
||||
|
||||
Reference in New Issue
Block a user