您可以通过不尝试移出借用价值来避免移出借用价值:
extern crate futures;
use futures::prelude::*;
struct Message;
struct Websocket;
impl Stream for Websocket {
type Item = Message;
type Error = ();
fn poll(&mut self) -> Result<Async<Option<Self::Item>>, Self::Error> {
Err(())
}
}
impl Iterator for Websocket {
type Item = Message;
fn next(&mut self) -> Option<Self::Item> {
let a = Stream::take(self, 1);
let mut b = a.wait();
let c = Iterator::next(&mut b);
c.and_then(Result::ok)
}
}
fn main() {}
没必要打电话
Stream::by_ref
因为起始类型已经是
&mut Websocket
,所以我把它移走了。
如果需要,可以将它们重新组合为一行:
fn next(&mut self) -> Option<Self::Item> {
Stream::take(self, 1)
.wait()
.next()
.and_then(Result::ok)
}