I am trying to read a line from a rustls::StreamOwned
object. My first instinct was to wrap it in a BufReader
, but the problem is that I need to be able to interleave my read_line()
calls with write()
calls, and I cannot use the underlying stream while BufReader
has a mutable reference to it. What is the idiomatic way to solve this problem?
Sample Code:
let stream: rustls::StreamOwned = //blah
let r = BufReader::new(stream) // Can't pass a reference here since &rustls::StreamOwned doesn't implement the read trait
loop {
let line: String;
r.read_line(&line);
stream.write(b"ping"); // Will fail to compile since r still owns the stream
}
Similar Question:
How to use a file with a BufReader and still be able to write to it?
The difference is that the reference type of the type I am dealing with does not implement the Read
trait, so I cannot simply pass a reference to the BufReader
.