Fn-like AsyncToString
All checks were successful
buildbot/mdbook test Build done.

This commit is contained in:
AF 2023-12-25 09:37:48 +00:00
parent dcd9e832e2
commit 7d27e3ca5e
2 changed files with 8 additions and 6 deletions

5
README.md Normal file
View File

@ -0,0 +1,5 @@
# Rust exercises
```sh
cargo watch -cs "mdbook test ."
```

View File

@ -5,15 +5,12 @@ Define the `AsyncToString` trait to make this compile and pass tests (don't edit
```rust,ignore,mdbook-runnable ```rust,ignore,mdbook-runnable
# extern crate futures; # extern crate futures;
# use futures::{Future, executor::block_on}; # use futures::{Future, executor::block_on};
# trait AsyncToStringRef<'a> { type F: 'a + Future<Output = String>; fn to_string(&'a self, s: &'a str) -> Self::F; } # trait AsyncToStringRef<'a>: Fn(&'a str) -> Self::F { type F: 'a + Future<Output = String>; }
# impl<'a, F: 'a + Future<Output = String>, T: Fn(&'a str) -> F> AsyncToStringRef<'a> for T { # impl<'a, F: 'a + Future<Output = String>, T: Fn(&'a str) -> F> AsyncToStringRef<'a> for T { type F = F; }
# type F = F;
# fn to_string(&'a self, s: &'a str) -> Self::F { self(s) }
# }
# trait AsyncToString: for<'a> AsyncToStringRef<'a> {} # trait AsyncToString: for<'a> AsyncToStringRef<'a> {}
# impl<T: for<'a> AsyncToStringRef<'a>> AsyncToString for T {} # impl<T: for<'a> AsyncToStringRef<'a>> AsyncToString for T {}
async fn test_generic(s: &str, f: impl AsyncToString) -> String { 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 { async fn to_string_async(s: &str) -> String {