Skip to content

Commit

Permalink
Fix a compile error
Browse files Browse the repository at this point in the history
Not sure how I didn't catch this earlier. The `output` is borrowed by
the future and can't be returned. This can be fixed by using a `Cell` to
share the value with the future and then replacing the inner value.

Signed-off-by: John Nunley <[email protected]>
  • Loading branch information
notgull committed Oct 15, 2023
1 parent 5d5edcd commit 248c21e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Public License along with `async-winit`. If not, see <https://www.gnu.org/licens
//! `winit` applications. The `Filter` type can be provided events, and will send those events to this
//! library's event handlers.

use std::cell::Cell;
use std::cmp;
use std::future::Future;
use std::pin::Pin;
Expand Down Expand Up @@ -133,11 +134,11 @@ impl<TS: ThreadSafety> Filter<TS> {
F: Future,
{
// Create a future that can be polled freely.
let mut output = ReturnOrFinish::Output(());
let output = Cell::new(ReturnOrFinish::Output(()));
let future = {
let output = &mut output;
let output = &output;
async move {
*output = ReturnOrFinish::FutureReturned(future.await);
output.set(ReturnOrFinish::FutureReturned(future.await));
}
};
futures_lite::pin!(future);
Expand Down Expand Up @@ -264,7 +265,7 @@ impl<TS: ThreadSafety> Filter<TS> {
}

// Return the output if any.
output
output.replace(ReturnOrFinish::Output(()))
}
}

Expand Down

0 comments on commit 248c21e

Please sign in to comment.