I'm learning Rust with the document on the official website.
I'm reading the part whose title is Build a Single-Thread Web Server.
The example code is
fn handle_connection(mut stream: TcpStream) {
let buf_reader = BufReader::new(&mut stream);
let http_request: Vec<_> = buf_reader
.lines()
.map(|result| result.unwrap())
.take_while(|line| !line.is_empty())
.collect();
println!("Request: {:#?}", http_request);
}
But when I use the filter()
instead of the take_while()
, the thread will being blocked.
Isn't it like the title says, the lines
iterator doesn't return None?