ostrya-core 0.18.0

ostree object model, checksums, on-disk format primitives, and typed config
Documentation
//! The value in effect of a key, and its source.

/// The value in effect of a key, and where it comes from.
///
/// A read takes the first source that gives a value, in this order:
///
/// 1. [`Forced`](Lookup::Forced): an override of the handle that applies
///    whether the file sets the key or not.
/// 2. [`File`](Lookup::File): the value of the file.
/// 3. [`Fallback`](Lookup::Fallback): an override of the handle that applies
///    when the file does not set the key.
/// 4. [`Default`](Lookup::Default): the built-in default of the key.
///
/// `OpenOptions::force`, `OpenOptions::fallback`, and
/// `CreateOptions::fallback` set the overrides of a handle. The reads of
/// `RepoConfig` apply them. A [`ConfigView`](super::ConfigView), a
/// [`Section`](super::Section), and a `RepoConfig` with no handle, such as
/// the result of `RepoConfig::parse`, have no override, so their reads give
/// [`File`](Lookup::File) or [`Default`](Lookup::Default).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Lookup<V> {
    /// The value comes from an override of the handle that wins over the
    /// file. The value applies also when the file does not set the key.
    Forced(V),
    /// The value comes from the file.
    File(V),
    /// The value comes from an override of the handle for a key that the
    /// file does not set.
    Fallback(V),
    /// The value is the built-in default of the key.
    Default(V),
}

impl<V> Lookup<V> {
    /// Returns the value.
    pub fn value(&self) -> &V {
        match self {
            Lookup::Forced(v) | Lookup::File(v) | Lookup::Fallback(v) | Lookup::Default(v) => v,
        }
    }

    /// Returns the value by value.
    pub fn into_value(self) -> V {
        match self {
            Lookup::Forced(v) | Lookup::File(v) | Lookup::Fallback(v) | Lookup::Default(v) => v,
        }
    }
}