我从以下代码中收到警告:
trait AsyncClient {
async fn new(host: &str, port: u16) -> Self;
}
warning: opaque type `impl Future<Output = Self>` does not satisfy its associated type bounds
--> src/lib.rs:2:5
|
2 | async fn new(host: &str, port: u16) -> Self;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
::: /playground/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/future/future.rs:40:5
|
40 | type Output;
| ------------ this associated type bound is unsatisfied for `Self`
|
= note: `#[warn(opaque_hidden_inferred_bound)]` on by default
如何修复警告?
添加
: Sized
绑定解决了问题:
trait AsyncClient: Sized {
async fn new(host: &str, port: u16) -> Self;
}