From 7d27e3ca5ed7ac054279926a6bfad7de7296d5ed Mon Sep 17 00:00:00 2001 From: timofey Date: Mon, 25 Dec 2023 09:37:48 +0000 Subject: [PATCH] Fn-like AsyncToString --- README.md | 5 +++++ src/exercises/async_fn.md | 9 +++------ 2 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..646a85d --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# Rust exercises + +```sh +cargo watch -cs "mdbook test ." +``` diff --git a/src/exercises/async_fn.md b/src/exercises/async_fn.md index 5c2256b..a5f9149 100644 --- a/src/exercises/async_fn.md +++ b/src/exercises/async_fn.md @@ -5,15 +5,12 @@ Define the `AsyncToString` trait to make this compile and pass tests (don't edit ```rust,ignore,mdbook-runnable # extern crate futures; # use futures::{Future, executor::block_on}; -# trait AsyncToStringRef<'a> { type F: 'a + Future; fn to_string(&'a self, s: &'a str) -> Self::F; } -# impl<'a, F: 'a + Future, T: Fn(&'a str) -> F> AsyncToStringRef<'a> for T { -# type F = F; -# fn to_string(&'a self, s: &'a str) -> Self::F { self(s) } -# } +# trait AsyncToStringRef<'a>: Fn(&'a str) -> Self::F { type F: 'a + Future; } +# impl<'a, F: 'a + Future, T: Fn(&'a str) -> F> AsyncToStringRef<'a> for T { type F = F; } # trait AsyncToString: for<'a> AsyncToStringRef<'a> {} # impl AsyncToStringRef<'a>> AsyncToString for T {} async fn test_generic(s: &str, f: impl AsyncToString) -> String { - f.to_string(s).await + f(s).await } async fn to_string_async(s: &str) -> String {