Skip to content

Commit 5f5dc79

Browse files
committed
[unstable-rust] Use async_closure syntax.
Note: This causes type inference failures, requiring us to specify the closures’ parameter types explicitly. I gather from reading issue <rust-lang/rust#127781> that this may be rectified by using native `AsyncFnOnce` / `async FnOnce` syntax, but that currently cannot specify the `+ Send + 'static` bound without also using `return_type_notation`, which is an incomplete feature.
1 parent 7061e97 commit 5f5dc79

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

all-is-cubes-desktop/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(async_closure)]
12
#![feature(never_type)]
23

34
//! Components for creating a desktop application that renders interactive [`all_is_cubes`]
@@ -101,7 +102,7 @@ pub fn inner_main<Ren: Renderer, Win: Window>(
101102
.context("failed to configure session for recording")?;
102103
}
103104

104-
dsession.session.set_main_task(|mut ctx| async move {
105+
dsession.session.set_main_task(async move |mut ctx| {
105106
let universe_result: Result<Universe, anyhow::Error> = match universe_future.await {
106107
Ok(Ok(u)) => Ok(u),
107108
Ok(Err(e)) => {

all-is-cubes-desktop/src/session.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use all_is_cubes::universe::Universe;
99
use all_is_cubes::universe::UniverseStepInfo;
1010
use all_is_cubes::util::ErrorChain;
1111
use all_is_cubes_render::camera::Viewport;
12-
use all_is_cubes_ui::apps::ExitMainTask;
12+
use all_is_cubes_ui::apps::{ExitMainTask, MainTaskContext};
1313

1414
use crate::Session;
1515

@@ -145,25 +145,26 @@ impl<Ren, Win: crate::glue::Window> DesktopSession<Ren, Win> {
145145

146146
// TODO: Also make a way to do this that isn't replacing the main task,
147147
// or that defines a way for the existing main task to coordinate.
148-
self.session.set_main_task(move |mut ctx| async move {
149-
// TODO: Offer confirmation before replacing the current universe.
150-
// TODO: Then open a progress-bar UI page while we load.
151-
152-
match loader_task.await.unwrap() {
153-
Ok(universe) => {
154-
ctx.set_universe(universe);
155-
}
156-
Err(e) => {
157-
ctx.show_modal_message(arcstr::format!(
158-
"Failed to load file '{path}':\n{e}",
159-
path = path.display(),
160-
e = ErrorChain(&e),
161-
));
148+
self.session
149+
.set_main_task(async move |mut ctx: MainTaskContext| {
150+
// TODO: Offer confirmation before replacing the current universe.
151+
// TODO: Then open a progress-bar UI page while we load.
152+
153+
match loader_task.await.unwrap() {
154+
Ok(universe) => {
155+
ctx.set_universe(universe);
156+
}
157+
Err(e) => {
158+
ctx.show_modal_message(arcstr::format!(
159+
"Failed to load file '{path}':\n{e}",
160+
path = path.display(),
161+
e = ErrorChain(&e),
162+
));
163+
}
162164
}
163-
}
164165

165-
ExitMainTask
166-
})
166+
ExitMainTask
167+
})
167168
}
168169

169170
/// Set the “fixed” window title — the portion of the title not determined by the universe,

all-is-cubes-ui/src/apps/session.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ mod tests {
13701370
let mut cameras = session.create_cameras(ListenableSource::constant(Viewport::ARBITRARY));
13711371
session.set_main_task({
13721372
let noticed_step = noticed_step.clone();
1373-
move |mut ctx| async move {
1373+
async move |mut ctx: MainTaskContext| {
13741374
eprintln!("main task: waiting for new universe");
13751375
let new_universe = recv.await.unwrap();
13761376
ctx.set_universe(new_universe);

all-is-cubes-ui/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(async_closure)]
12
#![feature(min_exhaustive_patterns)]
23
#![feature(never_type)]
34
#![feature(noop_waker)]

test-renderers/tests/wgpu-render.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Runs [`test_renderers::harness_main`] against [`all_is_cubes_gpu::in_wgpu`].
22
3+
#![feature(async_closure)]
4+
35
use clap::Parser as _;
46
use tokio::sync::OnceCell;
57

@@ -29,7 +31,7 @@ async fn main() -> test_renderers::HarnessResult {
2931
RendererId::Wgpu,
3032
test_renderers::SuiteId::Renderers,
3133
test_renderers::test_cases::all_tests,
32-
move || async move { get_factory().await.unwrap() },
34+
async move || get_factory().await.unwrap(),
3335
parallelism,
3436
)
3537
.await

0 commit comments

Comments
 (0)