Skip to content

Commit f20f94e

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 2f16bc4 commit f20f94e

File tree

6 files changed

+26
-21
lines changed

6 files changed

+26
-21
lines changed

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

+1
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`]

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

+19-18
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

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

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

168-
ExitMainTask
169-
})
169+
ExitMainTask
170+
})
170171
}
171172

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub fn inner_main<Ren: Renderer, Win: Window>(
8888
match *options {}
8989
}
9090

91-
dsession.session.set_main_task(|mut ctx| async move {
91+
dsession.session.set_main_task(async move |mut ctx| {
9292
let universe_result: Result<Universe, anyhow::Error> = match universe_task_future.await {
9393
// nested Results because one is template failure and the other is tokio JoinHandle failure
9494
Ok(Ok(u)) => Ok(u),

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

+1-1
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

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(async_closure)]
12
#![feature(never_type)]
23
#![feature(noop_waker)]
34

test-renderers/tests/wgpu-render.rs

+3-1
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)