pub struct Value {
    pub name: &'static str,
    /* private fields */
}
Expand description

Represents a setting value.

This is used for iterating values in Flags.

Fields§

§name: &'static str

The name of the setting associated with this value.

Implementations§

Gets the kind of setting.

Examples found in repository?
src/settings.rs (line 119)
118
119
120
121
122
123
124
125
126
    pub fn value_string(&self) -> String {
        match self.kind() {
            SettingKind::Enum => self.as_enum().map(|b| b.to_string()),
            SettingKind::Num => self.as_num().map(|b| b.to_string()),
            SettingKind::Bool => self.as_bool().map(|b| b.to_string()),
            SettingKind::Preset => unreachable!(),
        }
        .unwrap()
    }

Gets the enum value if the value is from an enum setting.

Examples found in repository?
src/settings.rs (line 120)
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    pub fn value_string(&self) -> String {
        match self.kind() {
            SettingKind::Enum => self.as_enum().map(|b| b.to_string()),
            SettingKind::Num => self.as_num().map(|b| b.to_string()),
            SettingKind::Bool => self.as_bool().map(|b| b.to_string()),
            SettingKind::Preset => unreachable!(),
        }
        .unwrap()
    }
}

impl fmt::Display for Value {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        if let Some(enum_variant) = self.as_enum() {
            write!(f, "{}={}", self.name, enum_variant)
        } else if let Some(num) = self.as_num() {
            write!(f, "{}={}", self.name, num)
        } else if let Some(b) = self.as_bool() {
            if b {
                write!(f, "{}=1", self.name)
            } else {
                write!(f, "{}=0", self.name)
            }
        } else {
            unreachable!()
        }
    }

Gets the numerical value if the value is from a num setting.

Examples found in repository?
src/settings.rs (line 121)
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    pub fn value_string(&self) -> String {
        match self.kind() {
            SettingKind::Enum => self.as_enum().map(|b| b.to_string()),
            SettingKind::Num => self.as_num().map(|b| b.to_string()),
            SettingKind::Bool => self.as_bool().map(|b| b.to_string()),
            SettingKind::Preset => unreachable!(),
        }
        .unwrap()
    }
}

impl fmt::Display for Value {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        if let Some(enum_variant) = self.as_enum() {
            write!(f, "{}={}", self.name, enum_variant)
        } else if let Some(num) = self.as_num() {
            write!(f, "{}={}", self.name, num)
        } else if let Some(b) = self.as_bool() {
            if b {
                write!(f, "{}=1", self.name)
            } else {
                write!(f, "{}=0", self.name)
            }
        } else {
            unreachable!()
        }
    }

Gets the boolean value if the value is from a boolean setting.

Examples found in repository?
src/settings.rs (line 122)
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
    pub fn value_string(&self) -> String {
        match self.kind() {
            SettingKind::Enum => self.as_enum().map(|b| b.to_string()),
            SettingKind::Num => self.as_num().map(|b| b.to_string()),
            SettingKind::Bool => self.as_bool().map(|b| b.to_string()),
            SettingKind::Preset => unreachable!(),
        }
        .unwrap()
    }
}

impl fmt::Display for Value {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        if let Some(enum_variant) = self.as_enum() {
            write!(f, "{}={}", self.name, enum_variant)
        } else if let Some(num) = self.as_num() {
            write!(f, "{}={}", self.name, num)
        } else if let Some(b) = self.as_bool() {
            if b {
                write!(f, "{}=1", self.name)
            } else {
                write!(f, "{}=0", self.name)
            }
        } else {
            unreachable!()
        }
    }

Builds a string from the current value

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.