mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-27 12:11:15 -03:00
Replace maybe_t::missing_or_empty with a more Rust-friendly helper
There are many places where we want to treat a missing variable the same as a variable with an empty value. In C++ we handle this by branching on maybe_t<env_var_t>::missing_or_empty(). If it returns false, we go on to access maybe_t<env_var_t>::value() aka operator*. In Rust, Environment::get() will return an Option<EnvVar>. We could define a MissingOrEmpty trait and implement it for Option<EnvVar>. However that will still leave us with ugly calls to Option::unwrap() (by convention Rust does use shorthands like *). Let's add a variable getter that returns none for empty variables.
This commit is contained in:
@@ -353,13 +353,13 @@ static base_directory_t make_base_directory(const wcstring &xdg_var,
|
||||
// uvars are available.
|
||||
const auto &vars = env_stack_t::globals();
|
||||
base_directory_t result{};
|
||||
const auto xdg_dir = vars.get(xdg_var, ENV_GLOBAL | ENV_EXPORT);
|
||||
if (!xdg_dir.missing_or_empty()) {
|
||||
const auto xdg_dir = vars.get_unless_empty(xdg_var, ENV_GLOBAL | ENV_EXPORT);
|
||||
if (xdg_dir) {
|
||||
result.path = xdg_dir->as_string() + L"/fish";
|
||||
result.used_xdg = true;
|
||||
} else {
|
||||
const auto home = vars.get(L"HOME", ENV_GLOBAL | ENV_EXPORT);
|
||||
if (!home.missing_or_empty()) {
|
||||
const auto home = vars.get_unless_empty(L"HOME", ENV_GLOBAL | ENV_EXPORT);
|
||||
if (home) {
|
||||
result.path = home->as_string() + non_xdg_homepath;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user