Skip to content

Commit 7e9ec2f

Browse files
committed
[unstable-rust] Use feature(async_closure).
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 cannot yet be used upon `F: FnOnce()` bounds, as opposed to non-`Fn` trait bounds.
1 parent b37fa16 commit 7e9ec2f

File tree

9 files changed

+31
-24
lines changed

9 files changed

+31
-24
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

all-is-cubes-desktop/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(never_type)]
23

34
//! Components for creating a desktop application that renders interactive [`all_is_cubes`]

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use all_is_cubes::universe::Universe;
1414
use all_is_cubes::universe::UniverseStepInfo;
1515
use all_is_cubes::util::ErrorChain;
1616
use all_is_cubes_render::camera::Viewport;
17-
use all_is_cubes_ui::apps::ExitMainTask;
17+
use all_is_cubes_ui::apps::{ExitMainTask, MainTaskContext};
1818

1919
use crate::Session;
2020

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

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

173-
ExitMainTask
174-
})
174+
ExitMainTask
175+
})
175176
}
176177

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub fn inner_main<Ren: Renderer, Win: Window>(
8787
match *options {}
8888
}
8989

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

all-is-cubes-server/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
4545
tower-http = { version = "0.5.0", features = ["fs"] }
4646

4747
[dev-dependencies]
48-
async_fn_traits = { workspace = true }
4948
# Note that with default features disabled, reqwest has no TLS/SSL support.
5049
# This is usable because we are only using it to talk to the local server.
5150
reqwest = { version = "0.12.2", default-features = false }

all-is-cubes-server/tests/http.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
#![feature(async_closure)]
2+
13
//! Test starting and contacting the web server, externally.
24
35
use std::process::Stdio;
46

5-
use async_fn_traits::AsyncFnOnce1;
67
use reqwest::header::HeaderValue;
78
use reqwest::Url;
89
use tokio::io::AsyncBufReadExt;
910

10-
async fn with_server<F: AsyncFnOnce1<Url, Output = ()>>(client_source: &'static str, f: F) {
11+
async fn with_server<F: async FnOnce(Url)>(client_source: &'static str, f: F) {
1112
let mut server = tokio::process::Command::new(env!("CARGO_BIN_EXE_aic-server"))
1213
.arg("--client-source")
1314
.arg(client_source)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ mod tests {
13771377
let mut cameras = session.create_cameras(ListenableSource::constant(Viewport::ARBITRARY));
13781378
session.set_main_task({
13791379
let noticed_step = noticed_step.clone();
1380-
move |mut ctx| async move {
1380+
async move |mut ctx: MainTaskContext| {
13811381
eprintln!("main task: waiting for new universe");
13821382
let new_universe = recv.await.unwrap();
13831383
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(never_type)]
23
#![feature(noop_waker)]
34

test-renderers/tests/wgpu-render.rs

Lines changed: 5 additions & 0 deletions
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,6 +31,9 @@ async fn main() -> test_renderers::HarnessResult {
2931
RendererId::Wgpu,
3032
test_renderers::SuiteId::Renderers,
3133
test_renderers::test_cases::all_tests,
34+
// TODO: Change this to
35+
// async move |label| { ... },
36+
// when <https://github.com/rust-lang/rust/issues/129811> is fixed.
3237
move |label| async move { get_factory(label).await.unwrap() },
3338
parallelism,
3439
)

0 commit comments

Comments
 (0)