This commit is contained in:
parent
dcd9e832e2
commit
7d27e3ca5e
5
README.md
Normal file
5
README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Rust exercises
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo watch -cs "mdbook test ."
|
||||||
|
```
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user