Stuck at this stage.
Here’s the code (Rust) :
use std::io::{BufRead, BufReader, Read, Write};
#[allow(unused_imports)]
use std::net::TcpListener;
fn main() {
let listener = TcpListener::bind("127.0.0.1:4221").unwrap();
for stream in listener.incoming() {
match stream {
Ok(mut stream) => {
let buf_reader = std::io::BufReader::new(&mut stream);
let request_line = buf_reader.lines().next().unwrap().unwrap();
let response = match request_line.as_str() {
"GET / HTTP/1.1" => "HTTP/1.1 200 OK\r\n\r\n",
_ => "HTTP/1.1 404 Not Found\r\n\r\n",
};
stream.write_all(response.as_bytes()).unwrap();
}
Err(e) => {
println!("error: {}", e);
}
}
}
}
Error:
remote: [compile] Compiling codecrafters-http-server v0.1.0 (/app)
remote: [compile] warning: unused `Result` that must be used
remote: [compile] --> src/main.rs:16:17
remote: [compile] |
remote: [compile] 16 | stream.write("HTTP/1.1 200 OK\r\n\r\n".as_bytes());
remote: [compile] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
remote: [compile] |
remote: [compile] = note: this `Result` may be an `Err` variant, which should be handled
remote: [compile] = note: `#[warn(unused_must_use)]` on by default
remote: [compile] help: use `let _ = ...` to ignore the resulting value
remote: [compile] |
remote: [compile] 16 | let _ = stream.write("HTTP/1.1 200 OK\r\n\r\n".as_bytes());
remote: [compile] | +++++++
remote: [compile]
remote: [compile] warning: `codecrafters-http-server` (bin "codecrafters-http-server") generated 1 warning
remote: [compile] Finished `release` profile [optimized] target(s) in 0.96s
remote: [compile] Moved ./.codecrafters/run.sh → ./your_program.sh
remote: [compile] Compilation successful.
FYI: I am not using stream.write() but i am using stream.write_all(), don’t why it’s considering stream.write() and throwing error.