fizyr / subst

Apache License 2.0
10 stars 4 forks source link

Fallback to Env when variables missing some key #20

Open futurist opened 1 month ago

futurist commented 1 month ago

Like below:

match (&value, &variable.default) {
                (None, None) => {
                    // --- here also .get from Env for the key/value as fallback
                    return Err(error::NoSuchVariable {
                        position: variable.name_start,
                        name: variable.name.to_owned(),
                    }
                    .into());
                },
}
de-vri-es commented 3 weeks ago

This is currently already possible if you create a custom VariableMap and implement this logic there.

Or, you could simple create a map, fill it with entries from std::env::vars() and then insert other variables.

It would be possible to add combinators to variable maps, a bit like the combinators for iterators in the standard library. But I'm not sure if it would really be worth the added complexity.