我如何在未来的链中 read_until tokio::net::TcpStream?

How do I read_until the tokio::net::TcpStream in a future chain?

我想从 TcpStream 读取数据,直到遇到 '\0'。 问题是 tokio::io::read_until 需要流为 BufRead.

fn poll(&mut self) -> Poll<(), Self::Error> {
    match self.listener.poll_accept()? {
        Async::Ready((stream, _addr)) => {
            let task = tokio::io::read_until(stream, 0, vec![0u8; buffer])
                 .map_err(|_| ...)
                 .map(|_| ...);
            tokio::spawn(task);
        }
        Async::NotReady => return Ok(Async::NotReady),
    }
}

如何通过这种方式从 TcpStream 中读取数据?

阅读 BufRead 的文档,您将看到文本:

If you have something that implements Read, you can use the BufReader type to turn it into a BufRead.

fn example(stream: TcpStream) {
    io::read_until(std::io::BufReader::new(stream), 0, vec![]);
}