我有一个封装结构的File
结构,我希望这个结构实现AsyncRead
特征,以便可以使用它来代替File
代码的其他部分:
struct TwoWayFile<'a> {
reader: &'a File,
}
impl<'a> AsyncRead for TwoWayFile<'a> {
fn poll_read(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8],
) -> Poll<io::Result<usize>> {
self.reader.poll_read(cx, buf)
}
}
根据文档tokio::fs::File
已经实现tokio::io::AsyncRead
,但编译器说相反:
error[E0599]: no method named `poll_read` found for reference `&'a tokio::fs::file::File` in the current scope
--> src/main.rs:44:21
|
44 | self.reader.poll_read(cx, buf)
| ^^^^^^^^^ method not found in `&'a tokio::fs::file::File`
这里缺少什么?为什么我不能调用已经定义的方法File
?