I'm trying the following implementation, assuming that I will receive values through a callback from Websockets.
(Playground) this is worked.
The requirements are as follows.
- async callback
- Deserialize without copy(Serde calls it Zero-copy deserialization)
Then, I wanna add async
block to callback.
#[tokio::main]
async fn main() -> Result<()> {
let _ = run(|res| async { // <- Add `async` here!!
println!("{:?}", res);
})
.await;
Ok(())
}
I tried this.
// Callback trait
pub trait Callback<A>: for<'any> FnMut(A::V<'any>) -> Future<Output = ()> + Send
where
A: Arg,
{
}
impl<A, F> Callback<A> for F
where
A: Arg,
F: for<'any> FnMut(A::V<'any>) -> Future<Output = ()> + Send,
{
}
Got err.
Compiling playground v0.0.1 (/playground)
error[E0782]: trait objects must include the `dyn` keyword
--> src/main.rs:58:55
|
58 | pub trait Callback<A>: for<'any> FnMut(A::V<'any>) -> Future<Output = ()> + Send
| ^^^^^^^^^^^^^^^^^^^
|
help: add `dyn` keyword before this trait
|
58 | pub trait Callback<A>: for<'any> FnMut(A::V<'any>) -> dyn Future<Output = ()> + Send
| +++
error[E0782]: trait objects must include the `dyn` keyword
--> src/main.rs:67:39
|
67 | F: for<'any> FnMut(A::V<'any>) -> Future<Output = ()> + Send,
| ^^^^^^^^^^^^^^^^^^^
|
help: add `dyn` keyword before this trait
|
67 | F: for<'any> FnMut(A::V<'any>) -> dyn Future<Output = ()> + Send,
| +++
For more information about this error, try `rustc --explain E0782`.
error: could not compile `playground` due to 2 previous errors
I may not have a good understanding of HRTB (Higher-Rank Trait Bounds.
How to add Future<Output = ()>
?