我想从一个流中格式化JSON对象,但是这个流是RwLock
中的包装器.因此,以下内容不起作用:
let mut stream:RwLockWriteGuard<'_, I2pStream> = wrapped_stream.write().await; // I2pStream implements the `Read` and `Write` Traits
let iterator = serde_json::Deserializer::from_reader(stream).into_iter::<serde_json::Value>();
for item in iterator {
// ...
}
...从the trait 'std::io::Read' is not implemented for 'tokio::sync::RwLockWriteGuard<'_, I2pStream>'
年开始.我预计RwLockWriteGuard
会实现其内容类型实现的所有特征,因为我还可以在写保护上调用read()
、read_buf(...)
等函数(这是Read
特征的函数).
那么,有没有办法让编译器知道我的写保护真的实现了std::io::Read
特征?或者有没有其他解决方案,比如将写保护包在读取器中?