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’ being Default + PartialEq to determine whether it’s the sentinel value; instead, taking is_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 use def to obtain the default value.

  • If the input is Some(None), or Some(Some(v)) where is_sentinel(v), the user has explicitly specified that this config item should be null/none/nothing, so we return None.

  • 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.