Futures 0.2.0 moving Context out of poll

In Future’s poll() method, you get a borrow of Context. You’re supposed to call Context.waker (https://docs.rs/futures/0.2.0/futures/task/struct.Context.html#method.waker) when the future is ready with data. But how do you get the waker out of the poll() method. I’d like to store it in another structure (with a different lifetime) with more knowledge of whether we’re ready to return data.

If you try to add lifetimes to anything in the poll() method, rust complains that the method signature no longer matches Future’s poll method. If you don’t, rust complains that the anonymous lifetime of the poll method doesn’t live long enough.

Any other structure must* be coming from a field of the Futures structure. (* Guess could use static/thread_local instead.)

Perhaps make your context an Option and use .take()?

As @jonh said, Waker is Clone so that’s the way to go.