Skip to content

Commit

Permalink
Rust 1.85: Use async closure syntax.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kpreid committed Dec 28, 2024
1 parent a11611b commit 2890c82
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 25 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 19 additions & 18 deletions all-is-cubes-desktop/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use all_is_cubes::universe::Universe;
use all_is_cubes::universe::UniverseStepInfo;
use all_is_cubes::util::ErrorChain;
use all_is_cubes_render::camera::Viewport;
use all_is_cubes_ui::apps::ExitMainTask;
use all_is_cubes_ui::apps::{ExitMainTask, MainTaskContext};

use crate::Session;

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

// TODO: Also make a way to do this that isn't replacing the main task,
// or that defines a way for the existing main task to coordinate.
self.session.set_main_task(move |mut ctx| async move {
// TODO: Offer confirmation before replacing the current universe.
// TODO: Then open a progress-bar UI page while we load.

match loader_task.await.unwrap() {
Ok(universe) => {
ctx.set_universe(universe);
}
Err(e) => {
ctx.show_modal_message(arcstr::format!(
"Failed to load file '{path}':\n{e}",
path = path.display(),
e = ErrorChain(&e),
));
self.session
.set_main_task(async move |mut ctx: MainTaskContext| {
// TODO: Offer confirmation before replacing the current universe.
// TODO: Then open a progress-bar UI page while we load.

match loader_task.await.unwrap() {
Ok(universe) => {
ctx.set_universe(universe);
}
Err(e) => {
ctx.show_modal_message(arcstr::format!(
"Failed to load file '{path}':\n{e}",
path = path.display(),
e = ErrorChain(&e),
));
}
}
}

ExitMainTask
})
ExitMainTask
})
}

/// Set the “fixed” window title — the portion of the title not determined by the universe,
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-desktop/src/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn inner_main<Ren: Renderer, Win: Window>(
match *options {}
}

dsession.session.set_main_task(|mut ctx| async move {
dsession.session.set_main_task(async move |mut ctx| {
let universe_result: Result<Universe, anyhow::Error> = match universe_task_future.await {
// nested Results because one is template failure and the other is tokio JoinHandle failure
Ok(Ok(u)) => Ok(u),
Expand Down
1 change: 0 additions & 1 deletion all-is-cubes-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
tower-http = { version = "0.6.2", features = ["fs"] }

[dev-dependencies]
async_fn_traits = { workspace = true }
# Note that with default features disabled, reqwest has no TLS/SSL support.
# This is usable because we are only using it to talk to the local server.
reqwest = { version = "0.12.2", default-features = false }
Expand Down
3 changes: 1 addition & 2 deletions all-is-cubes-server/tests/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
use std::process::Stdio;

use async_fn_traits::AsyncFnOnce1;
use reqwest::header::HeaderValue;
use reqwest::Url;
use tokio::io::AsyncBufReadExt;

async fn with_server<F: AsyncFnOnce1<Url, Output = ()>>(client_source: &'static str, f: F) {
async fn with_server<F: AsyncFnOnce(Url)>(client_source: &'static str, f: F) {
let mut server = tokio::process::Command::new(env!("CARGO_BIN_EXE_aic-server"))
.arg("--client-source")
.arg(client_source)
Expand Down
2 changes: 1 addition & 1 deletion all-is-cubes-ui/src/apps/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ mod tests {
let mut cameras = session.create_cameras(listen::constant(Viewport::ARBITRARY));
session.set_main_task({
let noticed_step = noticed_step.clone();
move |mut ctx| async move {
async move |mut ctx: MainTaskContext| {
eprintln!("main task: waiting for new universe");
let new_universe = recv.await.unwrap();
ctx.set_universe(new_universe);
Expand Down
2 changes: 1 addition & 1 deletion test-renderers/tests/wgpu-render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async fn main() -> test_renderers::HarnessResult {
RendererId::Wgpu,
test_renderers::SuiteId::Renderers,
test_renderers::test_cases::all_tests,
move |label| async move { get_factory(label).await.unwrap() },
async move |label| get_factory(label).await.unwrap(),
parallelism,
)
.await
Expand Down

0 comments on commit 2890c82

Please sign in to comment.