Skip to content

Commit

Permalink
[unstable-rust] 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` / `async FnOnce` syntax,
but that currently cannot specify the `+ Send + 'static` bound without
also using `return_type_notation`, which is an incomplete feature.
  • Loading branch information
kpreid committed Aug 15, 2024
1 parent c4a1a00 commit 85dc392
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
3 changes: 2 additions & 1 deletion all-is-cubes-desktop/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(async_closure)]
#![feature(never_type)]

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

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_future.await {
Ok(Ok(u)) => Ok(u),
Ok(Err(e)) => {
Expand Down
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 @@ -9,7 +9,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 @@ -145,25 +145,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-ui/src/apps/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ mod tests {
let mut cameras = session.create_cameras(ListenableSource::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
1 change: 1 addition & 0 deletions all-is-cubes-ui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(async_closure)]
#![feature(never_type)]
#![feature(noop_waker)]
#![feature(precise_capturing)]
Expand Down
4 changes: 3 additions & 1 deletion test-renderers/tests/wgpu-render.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Runs [`test_renderers::harness_main`] against [`all_is_cubes_gpu::in_wgpu`].
#![feature(async_closure)]

use clap::Parser as _;
use tokio::sync::OnceCell;

Expand Down Expand Up @@ -29,7 +31,7 @@ async fn main() -> test_renderers::HarnessResult {
RendererId::Wgpu,
test_renderers::SuiteId::Renderers,
test_renderers::test_cases::all_tests,
move || async move { get_factory().await.unwrap() },
async move || get_factory().await.unwrap(),
parallelism,
)
.await
Expand Down

0 comments on commit 85dc392

Please sign in to comment.