ボローチェッカーにまた出くわしてしまった…
enum TcpOrStr {
AddTcp(TcpStream),
RmTcp(SocketAddr),
Str(String, SocketAddr)
}
fn main() {
let listener = TcpListener::bind("127.0.0.1", 5555);
// bind the listener to the specified address
let mut acceptor = listener.listen();
let (tx, rx) = channel();
spawn(proc() {
let mut streams: Vec<TcpStream> = Vec::new();
loop {
let rxd: TcpOrStr = rx.recv();
match rxd {
AddTcp(stream) => {
streams.push(stream);
}
RmTcp(src) => {
// FIXME: O(n) operation
streams.retain(|mut strm|{ return strm.peer_name().unwrap() != src});
}
Str(line, src) => {
for stream in streams.iter_mut() {
if stream.peer_name().unwrap() == src {
continue;
}
let mut line_vec = line.clone().into_bytes();
let _ = stream.write(line_vec.as_mut_slice());
}
}
}
}
});
エラーは次のとおりです。
Compiling chat v0.1.0 (file:///home/chris/rust/chat)
src/chat.rs:29:55: 29:59 error: cannot borrow immutable dereference of `&`-pointer `*strm` as mutable
src/chat.rs:29 streams.retain(|mut strm|{ return strm.peer_name().unwrap() != src});
^~~~
error: aborting due to previous error
Could not compile `chat`.
ここで私の間違いは何ですか?