Skip to content

Instantly share code, notes, and snippets.

@jberkenbilt
Created November 30, 2024 13:43
Show Gist options
  • Save jberkenbilt/69483a9d84ef8dfb207b4ee3eb23017e to your computer and use it in GitHub Desktop.
Save jberkenbilt/69483a9d84ef8dfb207b4ee3eb23017e to your computer and use it in GitHub Desktop.
Go to Rust: 02 diff 01
@@ -25,17 +24,15 @@
/// call methods on the singleton. It takes a closure that takes a
/// &[Controller] and an arg, calls the closure using the singleton,
/// and returns the result.
-fn run_method<ArgT, ResultT, FnT>(
+fn run_method<ArgT, ResultT, FnT, Fut>(
f: FnT,
arg: ArgT,
) -> Result<ResultT, Box<dyn Error + Sync + Send>>
where
- // 2024-11-27: `async FnOnce` and `AsyncFnOnce` are unstable, and it is not yet decided
- // which syntax will win. See
- // - https://blog.rust-lang.org/inside-rust/2024/08/09/async-closures-call-for-testing.html
- // - https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Async.20closures.20bounds.20syntax
- FnT: async FnOnce(&Controller, ArgT) -> Result<ResultT, Box<dyn Error + Sync + Send>>,
- // OR:
+ FnT: FnOnce(&Controller, ArgT) -> Fut,
+ Fut: Future<Output = Result<ResultT, Box<dyn Error + Sync + Send>>>,
+ // Some day, one of these will work:
+ // FnT: async FnOnce(&Controller, ArgT) -> Result<ResultT, Box<dyn Error + Sync + Send>>,
// FnT: std::ops::AsyncFnOnce(&Controller, ArgT) -> Result<ResultT, Box<dyn Error + Sync + Send>>,
{
let lock = CONTROLLER.controller.read().unwrap();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment