pub enum ParamValue {
One(String),
Many(Vec<String>),
}Expand description
What one parameter holds: a value, or several.
ADR-0022. A parameter is single-valued unless its declaration says otherwise, and both shapes live in the same map because a binding stores one map whatever its parameters declared.
§Why an enum rather than always a list
Because of what it costs on disk. #[serde(untagged)] renders these as
app = "spotify" and apps = ["discord", "game"] in the same TOML table,
so a configuration written before lists existed parses unchanged and needs
no migration rung. Making every value a list would have rewritten every
binding anybody has, to express something almost none of them use.
It is also what 006-FR-024a-i asks for in the negative: a list “MUST be
widened rather than worked around with a delimiter convention the interface
cannot render”. A TOML array is how TOML writes a list. There is no
convention to learn, and nothing to escape.
Variants§
One(String)
One value. What every parameter was before ADR-0022.
Many(Vec<String>)
Several, in the order the user arranged them.
Implementations§
Source§impl ParamValue
impl ParamValue
Sourcepub fn one(&self) -> Option<&str>
pub fn one(&self) -> Option<&str>
The single value, or None if this holds a list.
Not the first element, deliberately. An addon that declared a
single-valued parameter and receives a list has been given something it
did not ask for, and quietly using the first entry would silently ignore
the rest — the failure being a key that mutes one of the three
applications somebody named. None reaches the required-parameter check
in Registry::perform and fails loudly instead.
Sourcepub fn all(&self) -> Vec<&str>
pub fn all(&self) -> Vec<&str>
Every value, whether this holds one or several.
A single value reads as a list of one, because an addon that declared
multiple should not have to care how the user happened to fill it in —
and a file written before lists existed contains exactly that case.
Empty strings are dropped for the same reason Self::one rejects
them: a cleared box is not a configured value.
Trait Implementations§
Source§impl Clone for ParamValue
impl Clone for ParamValue
Source§fn clone(&self) -> ParamValue
fn clone(&self) -> ParamValue
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ParamValue
impl Debug for ParamValue
Source§impl<'de> Deserialize<'de> for ParamValue
impl<'de> Deserialize<'de> for ParamValue
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl From<&str> for ParamValue
impl From<&str> for ParamValue
Source§impl PartialEq for ParamValue
impl PartialEq for ParamValue
Source§fn eq(&self, other: &ParamValue) -> bool
fn eq(&self, other: &ParamValue) -> bool
self and other values to be equal, and is used by ==.