Skip to content

Instantly share code, notes, and snippets.

@ngc0202
Last active September 5, 2016 20:10
Show Gist options
  • Save ngc0202/6106216de14fb6f0bc76f6ab1c549e0b to your computer and use it in GitHub Desktop.
Save ngc0202/6106216de14fb6f0bc76f6ab1c549e0b to your computer and use it in GitHub Desktop.
let scanner = iter(port_iter_res).map(|port: u16| {
let saddr = SocketAddr::new(addr, port);
let strm = pool2.handle().tcp_connect(&saddr);
strm.then(|r| -> Result<_, ()> {
let status = match r {
Ok(s) => {
let _ = s.shutdown(Shutdown::Both);
"open"
}
Err(_) => "closed",
};
println!("{}/tcp\t{}", port, status);
Ok(())
})
});
pool.run(scanner.into_future());
/*
src\main.rs:90:2: 90:6 error: cannot borrow `pool` as mutable because it is also borrowed as immutable [E0502]
src\main.rs:90 pool.run(scanner.into_future());
^~~~
src\main.rs:72:43: 72:54 note: immutable borrow occurs here
src\main.rs:72 let scanner = iter(port_iter_res).map(|port: u16| {
^~~~~~~~~~~
src\main.rs:91:1: 91:2 note: immutable borrow ends here
src\main.rs:91 }
^
src\main.rs:74:17: 74:21 note: previous borrow occurs due to use of `pool` in closure
src\main.rs:74 let strm = pool.handle().tcp_connect(&saddr);
^~~~
src\main.rs:90:2: 90:6 help: run `rustc --explain E0502` to see a detailed explanation
src\main.rs:75:16: 75:36 error: `port` does not live long enough
src\main.rs:75 strm.then(|r| -> Result<_, ()> {
^~~~~~~~~~~~~~~~~~~~
src\main.rs:88:8: 91:2 note: reference must be valid for the block suffix following statement 5 at 88:7...
src\main.rs:88 });
^
src\main.rs:72:55: 88:6 note: ...but borrowed value is only valid for the scope of function body at 72:54
src\main.rs:72 let scanner = iter(port_iter_res).map(|port: u16| {
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment