-2

In trying to adapt an example server, not sure what to make of this behaviour where the TcpStream I'm asking for and the one I'm getting appear to be entirely different.

Example struct definition:

use mio::tcp::TcpStream;

struct Connection {
    socket: TcpStream
}

Later there's a function defined for 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)
        };

An error on write_slice shows up with:

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

Now std::net::tcp::TcpStream doesn't implement this, but the mio::tcp::TcpStream does. Why would one get substituted for the other?

Setting this as an alias, use mil::tcp::TcpStream as MioTcpStream doesn't affect this either.

tadman
  • 208,517
  • 23
  • 234
  • 262
  • Do you have a `use std::net::tcp::TcpStream;` anywhere in your project? – A.B. Jun 29 '15 at 21:21
  • Not anywhere I know of. If I include that the compiler complains about conflicting `TcpStream` definitions. – tadman Jun 29 '15 at 21:26

1 Answers1

2

It turns out this is a problem with the published version of the mio package.

Adding the following to Cargo.toml pulls down and uses the latest working version:

[dependencies.mio]
git = "https://github.com/carllerche/mio.git"
tadman
  • 208,517
  • 23
  • 234
  • 262