rust - error: the type of this value must be known in this context -
I'm writing a simple TCP chat engine to learn the ladder.
Use std:: Io :: {TcpListener, TcpStream}; Use std :: io :: {acceptor, listener}; ANIM Streamorisis {SRM (TCPSTream), SLC (UIT, [U8,. 1024]) FN Main () {Hedge = TCPLSToner :: Bind ("127.0.0.1", 5555); // Listened to the specified address; mut accept = listener.listen (); Let's (tx, rx) = channel (); Squad (repeat streams: VAC & TC; TCPstream> = VACE :: new (match) RX RCV (SRM (MT stream) => {streams.push (stream)}} SLC ( Lane, Buf) => {stream.write (buf.slice (0, len));}}}}; // Acceptable and processed for the stream in streams.iter (stream) Increase a new task for eachbody for the incoming (stream) {match stream {error (E) => (/) connection failed * /} OK (mute (Stream) = & gt; {// Connection tx.Send succeeded (SRD (stream.clone ()); Let Tx2 = tx.clone (); spawn (proc () {mut buf: [u8, ..1024 ] = [0, ..1024]; loop {let's LAN = stream.read (buff); tx ss (buff)}}}}}}}}}} / pre> fails to compile the above code:
Integrate Chat v0.1.0 (file: // / home / chris / rust / chat) src / chat rs: 20: 13: 20:29 Error: The value of this value should be referenced in src / chat.rs: 20 Strm (mut stream) => {^ ~~~~~~~~~~~~ ~~~ Error: aborting due to previous error 'chat' compilation Could not. What's the reason?
The known value is , as enum as TcpStream . How can I fix this code?
The problem is, when you match rx.recv () , The compiler does not know the type of this expression, as you announced the general use let's (tx, rx) = channel (); And he had no chance of estimating the normal type so far.
Plus, because it is to check that you cover the pattern properly, it can not use the pattern to guess the pattern itself. You must explicitly declare it like this:
let's (tx, rx) = channel :: & lt; Stream Orssis & gt; ();
Comments
Post a Comment