I have a TcpStream, and i'm trying to create a dedicated thread to read from TcpStream and the main thread should do the write only, so i wrapped the TcpStream inside an Arc to share ownership.
Here is my code
fn main() {
let mut tcp_stream = TcpStream::connect("127.0.0.1:8080").unwrap();
let tcp_stream = Arc::new(&mut tcp_stream);
}
fn read_from_stream(tcp_stream: Arc<&mut TcpStream>) {
let mut buffer = String::new();
tcp_stream.read_to_string(&mut buffer);
}
I got the error Cannot borrow data in Arc as mutable. But the tcp_stream needs to be mutable in order to call read_to_string method.
What should i do to make this work?