Closed
Description
Code
use std::collections::HashMap;
fn handle(request: &str) -> String {
let parsed = parse(request);
let routed = route(parsed);
format_response(routed)
}
fn parse(request: &str) -> HashMap<String, String> {
let first_line = request.lines().next().unwrap_or("");
let words: Vec<&str> = first_line.split_whitespace().collect();
let mut conv = HashMap::new();
if let [method, path, _protocol @ ..] = &words[..] {
conv.insert("method".to_string(), words[0].to_string());
conv.insert("path".to_string(), words[1].to_string());
}
conv.insert("resp_body".to_string(), "".to_string());
conv
}
fn route(mut conv: HashMap<String, String>) -> HashMap<String, String> {
//TODO - edit/create hashmap that has the response body
//in a immutable way
// Create a new HashMap with the existing data from conv
conv.insert("resp_body".to_string(), "This is about us".to_string());
conv
}
fn format_response(conv: HashMap<String, String>) -> String {
format!(
"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: {}\r\n\r\n{}",
conv.get("resp_body").unwrap_or(&"".to_string()).len(),
conv.get("resp_body").unwrap_or(&"".to_string())
)
}
fn main() {
}
Meta
rustc --version --verbose
:
<version>
Error output
thread 'copy LTO artifacts for 14fjghlwjticu4oo' panicked at 'no saved object file in work product', /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483\compiler\rustc_codegen_ssa\src\back\write.rs:890:10
stack backtrace:
0: 0x7ffdd7619de2 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha63cfe4b75b3ba72
1: 0x7ffdd7655d0b - core::fmt::write::h5f1cd682e23942b6
2: 0x7ffdd760ca2a - <std::io::IoSliceMut as core::fmt::Debug>::fmt::h6b970ebe775b9627
3: 0x7ffdd7619b2b - std::sys::common::alloc::realloc_fallback::h413616b22f3f3818
4: 0x7ffdd761d459 - std::panicking::default_hook::h0c26739d8a69e80d
5: 0x7ffdd761d0db - std::panicking::default_hook::h0c26739d8a69e80d
6: 0x7ffd8fb9d16d - rustc_driver[6d4b93d6bcfc3289]::describe_lints
7: 0x7ffdd761ddc0 - std::panicking::rust_panic_with_hook::hdf07e8fcc7859773
8: 0x7ffdd761db1e - <std::panicking::begin_panic_handler::StrPanicPayload as core::panic::BoxMeUp>::get::hac35d15c76f5304d
9: 0x7ffdd761aadf - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::ha63cfe4b75b3ba72
10: 0x7ffdd761d7d0 - rust_begin_unwind
11: 0x7ffdd768bb85 - core::panicking::panic_fmt::hd2b8fa31b060140f
12: 0x7ffdd7652ac0 - <core::panic::panic_info::PanicInfo as core::fmt::Display>::fmt::h5377e9fccca41389
13: 0x7ffdd7652a6b - <core::panic::panic_info::PanicInfo as core::fmt::Display>::fmt::h5377e9fccca41389
14: 0x7ffdd768bb49 - core::option::expect_failed::hed6ba619d7fd0fcb
15: 0x7ffd8d3dd742 - <rustc_codegen_llvm[8858754bf01e5222]::llvm_::ffi::Type>::i8p_llcx
16: 0x7ffd8d3d1009 - <rustc_codegen_llvm[8858754bf01e5222]::LlvmCodegenBackend as rustc_codegen_ssa[81e5edbff33a6ce5]::traits::backend::CodegenBackend>::link
17: 0x7ffd8d4173d7 - <rustc_codegen_llvm[8858754bf01e5222]::builder::Builder as rustc_codegen_ssa[81e5edbff33a6ce5]::traits::builder::BuilderMethods>::unchecked_smul
18: 0x7ffdd762fe9c - std::sys::windows::thread::Thread::new::h92ec69467f05d131
19: 0x7ffe0e197614 - BaseThreadInitThunk
20: 0x7ffe0f6e26b1 - RtlUserThreadStart
error: internal compiler error: unexpected panic
Backtrace
<backtrace>