在 tokio.rs 的文档中,我们看到以下代码片段。
// split the socket stream into readable and writable parts
let (reader, writer) = socket.split();
// copy bytes from the reader into the writer
let amount = io::copy(reader, writer);
我假设split
确实是Stream::split
,但是我无法理解这个特质如何适用于TcpStream
,因为流页面没有提到TcpStream
,反之亦然。
impl Trait for Type { ... }
。有时这段代码是由宏或其他东西生成的,但最终效果是一样的。 - ShepmasterTcpStream
文档时,你是否在页面上搜索了split
方法?链接为https://docs.rs/tokio/0.1.20/tokio/net/struct.TcpStream.html#impl-AsyncRead - Shepmaster