It took hours to figure out how to implement this in rust: https://github.com/sctb/lumen/blob/master/bin/lumen
If you want to see an "expert" programmer's attempt at making sense of the language, here you go: https://gist.github.com/shawwn/4d7a89188cac72f3e591f47c84d3c...
Now that it's done though, I see why people fall in love with Rust. It's really satisfying seeing Lumen's startup time drop from 200ms to 100ms.
But yes, like -- dude, at one point I just wanted to write a for loop like this, to grab some environment vars:
let mut lumen_host = "luajit";
let mut lua_path = "";
let mut node_path = "";
for (name, value) in env::vars() {
if name == "LUMEN_HOST" {
lumen_host = &value;
} else if name == "LUA_PATH" {
lua_path = &value;
} else if name == "NODE_PATH" {
node_path = &value;
}
}
println!("{} {} {} {}", bin, lumen_host, lua_path, node_path);
Good luck with that! I'm sure there's a way to coax Rust into please-allow-me-to-just-compile-this, but the borrow checker is a cruel taskmaster. Whatever the syntax is, that's not it, and spending literally an hour trying to figure out how to store an environment variable into a separate variable doesn't feel very productive.That said, Cargo is amazing. It's truly a wonderful, delightful piece of software. Cargo crates plus a dynamic language seems like a recipe for success.