Function tor_config::resolve_option

source ·
pub fn resolve_option<T, DF>(input: &Option<Option<T>>, def: DF) -> Option<T>
where T: Clone + Default + PartialEq, DF: FnOnce() -> Option<T>,
Expand description

Resolves an Option<Option<T>> (in a builder) into an Option<T>

  • 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(Default::default())), 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

For consistency with other APIs in Arti, when using this, do not pass setter(strip_option) to derive_builder.

§⚠ Stability Warning ⚠

We may significantly change this so that it is an method in an extension trait.