Struct kconfig_represent::Variant
source · pub struct Variant { /* private fields */ }
Expand description
An evaluated value represents the value of a an expression after evaluation.
Implementations
sourceimpl Variant
impl Variant
pub fn datatype(&self) -> VariantDataType
pub fn new_typed(vdt: &VariantDataType) -> Self
pub fn convert_into(&self, vdt: &VariantDataType) -> Self
sourcepub fn to_bool(&self) -> bool
pub fn to_bool(&self) -> bool
Converts the variant into a bool.
If the variant contains a string value, the “n” or “N” string convert into a false boolean, other strings convert into a true boolean.
If the variant contains a numeric value, either an integer or hexadecimal value, a 0 is converted into a false boolean, any other value into a true boolean.
If the variant contains a tristate value, only the false tristate value will be converted into a false boolean, either a true or maybe tristate value will be converted into a true value.
If the variant contains a boolean value, it will be returned as is.
sourcepub fn to_tristate(&self) -> Tristate
pub fn to_tristate(&self) -> Tristate
Converts the variant into a tristate.
If the variant contains a string value, the “n” or “N” string convert into a false tristate, the “m” or “M” strings convert into a maybe tristate, any other strings convert into a true tristate.
If the variant contains a numeric value, either an integer or hexadecimal value, a 0 is converted into a false tristate, any other value into a true tristate.
If the variant contains a tristate value, it will be returned as is.
If the variant contains a boolean value, it will be converted as tristate.
sourcepub fn to_hex(&self) -> Hex
pub fn to_hex(&self) -> Hex
Converts the variant into a hexadecimal value.
If the variant contains a string value, an attempt will be made to convert the string in to an integer. If that fails, and the string contains a “n” or “N” value, it is converted into 0x00, otherwise it is interpreted as 0x01.
If the variant contains a numeric value, either an integer or hexadecimal value, it will be returned as is, as hexadecimal representation. If the value is an integer, the sign will be converted.
If the variant contains a tristate value, if the tristate is a false value, it will be converted as 0x00, otherwise it will be converted as 0x01.
If the variant contains a boolean value, if the boolean is a false value, it will be converted as 0x00, otherwise it will be converted as 0x01.
sourcepub fn to_int(&self) -> i64
pub fn to_int(&self) -> i64
Converts the variant into an integer value.
If the variant contains a string value, an attempt will be made to convert the string in to an integer. If that fails, and the string contains a “n” or “N” value, it is converted into 0, otherwise it is interpreted as 1.
If the variant contains a numeric value, either an integer or hexadecimal value, it will be returned as is, as hexadecimal representation. If the value is a hexadecimal, the sign will be converted.
If the variant contains a tristate value, if the tristate is a false value, it will be converted as 0, otherwise it will be converted as 1.
If the variant contains a boolean value, if the boolean is a false value, it will be converted as 0, otherwise it will be converted as 1.
sourcepub fn parse(v: &str) -> Self
pub fn parse(v: &str) -> Self
Parses a given string, and attempts to return the closest matching variant belonging to the string. If the string contains a “y” or “Y” value, it is converted to a boolean true value, if the string contains a “n” or “N” value, it is converted to a boolean false value, if the string contains a “m” or “M” value, it is converted into a tristate maybe value.
If none of the above are true, an attempt is made to parse the string as hexadecimal and integer values. If unsuccessful, it is considered a normal string.
sourcepub fn from_dot_config(v: &str) -> Self
pub fn from_dot_config(v: &str) -> Self
Converts a dot config value back into a Variant
sourcepub fn dot_config(&self) -> String
pub fn dot_config(&self) -> String
Converts the representation of the variant from a normal value to a .config representation, as used by the Kconfig intermediate format.
sourcepub fn transform(&self, vdt: VariantDataType) -> Variant
pub fn transform(&self, vdt: VariantDataType) -> Variant
Transforms the variant from the current variant type, into the given variant type
Trait Implementations
sourceimpl From<Variant> for MutationStart
impl From<Variant> for MutationStart
sourceimpl Into<Hex> for Variant
impl Into<Hex> for Variant
sourcefn into(self) -> Hex
fn into(self) -> Hex
Converts the variant into a hexadecimal value, using the
Self::to_hex()
function.
sourceimpl Into<String> for Variant
impl Into<String> for Variant
sourcefn into(self) -> String
fn into(self) -> String
Converts the variant into a string, using the
Self::to_string()
function.
sourceimpl Into<Tristate> for Variant
impl Into<Tristate> for Variant
sourcefn into(self) -> Tristate
fn into(self) -> Tristate
Converts the variant into a tristate value, using the
Self::to_tristate()
function.
sourceimpl Into<bool> for Variant
impl Into<bool> for Variant
sourcefn into(self) -> bool
fn into(self) -> bool
Converts the variant into a boolean value, using the
Self::to_bool()
function.
sourceimpl Into<i64> for Variant
impl Into<i64> for Variant
sourcefn into(self) -> i64
fn into(self) -> i64
Converts the variant into an integer value, using the
Self::to_int()
function.
sourceimpl Not for Variant
impl Not for Variant
sourceimpl Ord for Variant
impl Ord for Variant
sourcefn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
If self and other are both of integer or hexadecimal type, then comparison will be performed by integer comparison.
If self and other are both of boolean or tristate type, then comparison will be performed on tristate value, thus y > m > n.
If one is of type boolean/tristate and the other is of type integer/hexadecimal, the integer/hexadecimal type will be converted to it’s boolean equivalent, then compared
Everything else will be compared as if it were two string types.
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
sourceimpl PartialOrd<Variant> for Variant
impl PartialOrd<Variant> for Variant
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more