Why isn't `default_env!` a built-in macro?

option_env! is great and all but it can’t be used inside of macros that take literals. default_env! tries to solve this and seems generally useful enough that it could be included alongside std::*env!. Is there any reason why this wasn’t already the case?

In general, the answer to “why is x not in std?” is “because it does not have to be.”

The default_env behavior is somewhat niche – I rarely want a surprise empty string when an environment variable isn’t set – and it is clearly implementable in a crate (since you linked to it), so it doesn’t seem like an obvious candidate for std to me.

(Why is env! in std, then? Because we didn’t have proc macros originally, and those are necessary to implement it in a crate.)

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.