I'm playing with a function that handles a TCP connection:
use std::{io::Write, net::TcpStream, sync::Arc};
fn handle_connection(stream: TcpStream) {
let data = "Hello!\n";
let stream_arc = Arc::new(stream);
let mut s: &TcpStream = &*stream_arc; //let mut s = Deref::deref(&stream_arc);
s.write_all(data.as_bytes()).unwrap(); //same as Write::write_all(&mut s, data.as_bytes()).unwrap();
}
I can't figure out why Rust doesn't complain about Write::write_all
since s
is not a mutable reference. I noticed also that removing mut
from s
compilation fails. Am I missing some trait implementation that permits this? Is this a way to mutably borrow from std::sync::Arc
?