mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-28 21:41: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:
@@ -123,8 +123,8 @@ static readb_result_t readb(int in_fd) {
|
||||
// Update the wait_on_escape_ms value in response to the fish_escape_delay_ms user variable being
|
||||
// set.
|
||||
void update_wait_on_escape_ms(const environment_t& vars) {
|
||||
auto escape_time_ms = vars.get(L"fish_escape_delay_ms");
|
||||
if (escape_time_ms.missing_or_empty()) {
|
||||
auto escape_time_ms = vars.get_unless_empty(L"fish_escape_delay_ms");
|
||||
if (!escape_time_ms) {
|
||||
wait_on_escape_ms = WAIT_ON_ESCAPE_DEFAULT;
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user