Skip to main content

ParamValue

Enum ParamValue 

Source
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

Source

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.

Source

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

Source§

fn clone(&self) -> ParamValue

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ParamValue

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ParamValue

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&str> for ParamValue

Source§

fn from(v: &str) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for ParamValue

Source§

fn eq(&self, other: &ParamValue) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for ParamValue

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for ParamValue

Source§

impl StructuralPartialEq for ParamValue

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,