Any C++ replacement language should support all the features of C++ to be suitable...
Rust is doing everything it can here, these APIs are labelled unsafe, and on a system where they can work, they will work. You can see similar in the filesystem code. On Windows, or a modern Linux, you get what you'd like to have, and on somebody's SysV clone where that's not possible it's still not possible from Rust.
Rust has no reason to touch the original Unix API. Take a snapshot of the values at startup and write an API around that, any runtime modification of the Unix environment is suspect anyway and anyone who wants to deal with that rotten mess can jump through half a dozen hoops.
> Rust is doing everything it can here, these APIs are labelled unsafe
Unix gave us C, clearly Rust should have just labeled every C standard library function like malloc and free unsafe and thrown up their hands instead of introducing ownership semantics and all that messy compiler logic around it. After all Rust can't fix how Unix works, so they shouldn't have tried in the first place.
As a systems language, Rust must provide access to the APIs of the underlying system, and on UNIX, that’s, well, UNIX.
Let me clarify. There is no reason for std::env to be dragged down by UNIX, it could be its own, modern, safe thing with the Unix API living in std::pet_cemetary or some comparably clear namespace for people who have to pass runtime information to a C library through absolutely unsafe ways. Environment variables are usefull, the unix limitations make them less so.
It could be a completely separate "modern, safe thing" which roughly nobody has any use for and which would be confusing since what people want are environment variables and this would instead be its own "modern, safe thing" for some reason.
Mutex<HashMap<String,String>> is probably a reasonable "modern, safe thing" for the handful of people who actually would get value out of this, and the fact it's not labelled "Environment variables" because that's not what it is probably also avoids people who needed the actual environment variables cursing because they were hidden down the back of the sofa.
Why not? Is it the lack of race conditions? The lack of crashes or memory leaks? Is it the fact that you came up with it in five seconds and it is still a million times better than what we have? Or is it the fact that the holy book of Posix spells out how to do it badly in C and because of that we are never allowed to replace it with something better?