Struct cranelift_codegen::settings::Value
source · 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 strThe name of the setting associated with this value.
Implementations§
source§impl Value
impl Value
sourcepub fn as_enum(&self) -> Option<&'static str>
pub fn as_enum(&self) -> Option<&'static str>
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!()
}
}sourcepub fn as_num(&self) -> Option<u8>
pub fn as_num(&self) -> Option<u8>
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!()
}
}sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
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!()
}
}sourcepub fn value_string(&self) -> String
pub fn value_string(&self) -> String
Builds a string from the current value