We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use std::io::{Listener, Acceptor}; use std::io::net::ip::{SocketAddr, Ipv4Addr}; use std::io::net::tcp::{TcpListener, TcpAcceptor, TcpStream}; fn main () { let addr: SocketAddr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 3000 }; let listener: TcpListener = match TcpListener::bind(addr) { None => { error!("Failed to bind"); return; }, Some(l) => l }; let mut acceptor: TcpAcceptor = match listener.listen() { None => { error!("Failed to listen"); return; }, Some(a) => a }; let mut count: i32 = 0i32; loop { let mut stream: TcpStream = match acceptor.accept() { None => continue, Some(s) => s }; do spawn { stream.write_str("hello world\n"); count += 1; match stream.peer_name() { None => return, Some(p) => println(p.ip.to_str() + ":" + p.port.to_str()) }; match stream.socket_name() { None => return, Some(s) => println(s.ip.to_str() + ":" + s.port.to_str()) }; println!("{} connections", count); } } }
test.rs:26:7: 26:13 error: cannot borrow immutable captured outer variable in a heap closure as mutable test.rs:26 stream.write_str("hello world\n");
Why can't I close over the variable stream? Is there a way I can move it? @cmr and @dbaupp seem to think it's a bug.
The text was updated successfully, but these errors were encountered:
Closing as a dupe of #10617.
Sorry, something went wrong.
No branches or pull requests
Why can't I close over the variable stream? Is there a way I can move it? @cmr and @dbaupp seem to think it's a bug.
The text was updated successfully, but these errors were encountered: