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:
Johannes Altmanninger
2023-04-20 12:24:53 +02:00
parent 82a797db9c
commit 1df64a4891
15 changed files with 64 additions and 67 deletions

View File

@@ -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;
}