导入 mio::tcp::TcpStream 但得到 std::net::tcp::TcpStream
Importing mio::tcp::TcpStream but get std::net::tcp::TcpStream
在尝试调整 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
实现了。为什么一个会被另一个取代?
将此设置为别名,use mil::tcp::TcpStream as MioTcpStream
也不会影响。
原来这是 mio
包的发布版本的问题。
将以下内容添加到 Cargo.toml
下拉并使用最新的工作版本:
[dependencies.mio]
git = "https://github.com/carllerche/mio.git"
在尝试调整 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
实现了。为什么一个会被另一个取代?
将此设置为别名,use mil::tcp::TcpStream as MioTcpStream
也不会影响。
原来这是 mio
包的发布版本的问题。
将以下内容添加到 Cargo.toml
下拉并使用最新的工作版本:
[dependencies.mio]
git = "https://github.com/carllerche/mio.git"