Skip to content

Commit f0fe32f

Browse files
committed
Rust 1.85: 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` 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 f6d11dc commit f0fe32f

File tree

7 files changed

+23
-25
lines changed

7 files changed

+23
-25
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/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

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

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

170-
ExitMainTask
171-
})
171+
ExitMainTask
172+
})
172173
}
173174

174175
/// 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
@@ -43,7 +43,6 @@ tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
4343
tower-http = { version = "0.6.2", features = ["fs"] }
4444

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

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
33
use std::process::Stdio;
44

5-
use async_fn_traits::AsyncFnOnce1;
65
use reqwest::header::HeaderValue;
76
use reqwest::Url;
87
use tokio::io::AsyncBufReadExt;
98

10-
async fn with_server<F: AsyncFnOnce1<Url, Output = ()>>(client_source: &'static str, f: F) {
9+
async fn with_server<F: AsyncFnOnce(Url)>(client_source: &'static str, f: F) {
1110
let mut server = tokio::process::Command::new(env!("CARGO_BIN_EXE_aic-server"))
1211
.arg("--client-source")
1312
.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
@@ -1379,7 +1379,7 @@ mod tests {
13791379
let mut cameras = session.create_cameras(ListenableSource::constant(Viewport::ARBITRARY));
13801380
session.set_main_task({
13811381
let noticed_step = noticed_step.clone();
1382-
move |mut ctx| async move {
1382+
async move |mut ctx: MainTaskContext| {
13831383
eprintln!("main task: waiting for new universe");
13841384
let new_universe = recv.await.unwrap();
13851385
ctx.set_universe(new_universe);

test-renderers/tests/wgpu-render.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async fn main() -> test_renderers::HarnessResult {
2929
RendererId::Wgpu,
3030
test_renderers::SuiteId::Renderers,
3131
test_renderers::test_cases::all_tests,
32-
move |label| async move { get_factory(label).await.unwrap() },
32+
async move |label| get_factory(label).await.unwrap(),
3333
parallelism,
3434
)
3535
.await

0 commit comments

Comments
 (0)