Function tor_config::resolve_option_general
source · pub fn resolve_option_general<T, ISF, DF>(
input: Option<Option<&T>>,
is_sentinel: ISF,
def: DF
) -> Option<T>where
T: Clone,
DF: FnOnce() -> Option<T>,
ISF: FnOnce(&T) -> bool,
Expand description
Resolves an Option<Option<T>>
(in a builder) into an Option<T>
, more generally
Like resolve_option
, but:
-
Doesn’t rely on
T
’ beingDefault + PartialEq
to determine whether it’s the sentinel value; instead, takingis_explicit
. -
Takes
Option<Option<&T>>
which is more general, but less like the usual call sites. -
If the input is
None
, this indicates that the user did not specify a value, and we therefore usedef
to obtain the default value. -
If the input is
Some(None)
, orSome(Some(v)) where is_sentinel(v)
, the user has explicitly specified that this config item should be null/none/nothing, so we returnNone
. -
Otherwise the user provided an actual value, and we return
Some
of it.
See https://gitlab.torproject.org/tpo/core/arti/-/issues/488
⚠ Stability Warning ⚠
We may significantly change this so that it is an method in an extension trait.