我有以下类型:
pub type MessageStream = Pin<Box<dyn Stream<Item = Result<rtsp_types::Message<Body>, ReadError>> + Send>>;
Run Code Online (Sandbox Code Playgroud)
和一个结构成员:
stream: Option<MessageStream>,
Run Code Online (Sandbox Code Playgroud)
我这样称呼:
self.stream.as_mut().unwrap().poll_next();
Run Code Online (Sandbox Code Playgroud)
但我得到
116 | let response = self.stream.as_mut().unwrap().poll_next();
| ^^^^^^^^^ method not found in `&mut Pin<Box<(dyn futures::Stream<Item = std::result::Result<rtsp_types::Message<Body>, message_socket::ReadError>> + std::marker::Send + 'static)>>`
Run Code Online (Sandbox Code Playgroud)
在https://docs.rs/futures/0.2.0/futures/stream/trait.Stream.html上,它仅列出poll_next
,但into_future()
由于某种原因对我有用。
转向未来很好,但我也想这样做poll_next
,我正在尝试很多事情。
怎么了?
除非您正在编写Future
或执行程序,否则您可能不应该调用poll_next()
. 您应该在上下文中使用next()
from特征。StreamExt
async
use futures::StreamExt;
// ...
self.stream.as_mut().unwrap().next().await;
Run Code Online (Sandbox Code Playgroud)