rust - 导入 mio::tcp::TcpStream 但得到 std::net::tcp::TcpStream

标签 rust mio

在尝试改编 example server ,不知道如何理解这种行为,因为我要求的 TcpStream 和我得到的似乎完全不同。

示例结构定义:

use mio::tcp::TcpStream;

struct Connection {
    socket: TcpStream
}

稍后为 Connection 定义了一个函数:

fn writable(&mut self, event_loop: &mut EventLoop<Server>) -> Result<()> {
    loop {
        let (len, res) = {
            let buf = &self.buffer.bytes();
            let len = buf.len();
            let res = self.socket.write_slice(buf);
            (len, res)
        };

write_slice 的错误显示为:

error: type `std::net::tcp::TcpStream` does not implement any method in scope named `write_slice`

现在 std::net::tcp::TcpStream 没有实现这个,但是 mio::tcp::TcpStream做。为什么一个会被另一个取代?

将其设置为别名,将 mil::tcp::TcpStream 用作 MioTcpStream 也不会影响这一点。

最佳答案

事实证明这是mio 包的发布版本的问题。

将以下内容添加到 Cargo.toml 下拉并使用最新的工作版本:

[dependencies.mio]
git = "https://github.com/carllerche/mio.git"

关于rust - 导入 mio::tcp::TcpStream 但得到 std::net::tcp::TcpStream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31125287/

相关文章:

asynchronous - 将请求正文转发到 Actix-Web 中的响应

udp - 使用 mio 使用 UDP 并收到错误 "MutBuf is not implemented for the type MutSliceBuf"

rust - mio 负载较小的简单 TCP 服务器出现“连接被对等重置”错误

rust - 在 Rust 中给一个方法作为参数(Vec sort() 方法)

rust - 有没有办法将 `Vec<Vec<T>>` 转换为 `Vec<T>` ,将所有 `Vec<T>` 组合成一个 `Vec<T>` ?

rust - 如何处理 mio 中的错误?

rust - 从 mio::udp::UdpSocket.recv 接收部分 UDP 数据包

rust - 可变借用似乎超出了它的范围

parsing - 在 Rust 语言中将 String 解析为 Unsigned 的问题