Why does std::env::args allocate?

64 points Dr_Sloth0

Is there any good reason that std::env::args allocates always? Is there any platform on which the args could not be &'static OsStr instead of OsString? And why doesn't it use a Cow<'static, OsStr> which only allocates if necessary? Is there a good technical reason or some baggage? Would it make sense/is it possible to create a cross platform crate to give you the args without allocating, maybe even allowing to mutate them?

dtolnays argv crate does something similiar on Linux/Unix systems but doesn't allow mutating the args and also doesn't really work for windows and musl i think.

Thanks for your time :)