Variant

Struct Variant 

Source
pub struct Variant { /* private fields */ }
Expand description

An evaluated value represents the value of a an expression after evaluation.

Implementations§

Source§

impl Variant

Source

pub fn datatype(&self) -> VariantDataType

Source

pub fn new_typed(vdt: &VariantDataType) -> Self

Source

pub fn convert_into(&self, vdt: &VariantDataType) -> Self

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn from_dot_config(v: &str) -> Self

Converts a dot config value back into a Variant

Source

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.

Source

pub fn transform(&self, vdt: VariantDataType) -> Variant

Transforms the variant from the current variant type, into the given variant type

Trait Implementations§

Source§

impl Clone for Variant

Source§

fn clone(&self) -> Variant

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Variant

Source§

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

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

impl Display for Variant

Source§

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

Formats the display of the variant as value

Source§

impl From<&str> for Variant

Source§

fn from(v: &str) -> Self

Creates a variant from a string

Source§

impl From<Hex> for Variant

Source§

fn from(h: Hex) -> Self

Creates a variant form a hexadecimal value

Source§

impl From<String> for Variant

Source§

fn from(v: String) -> Self

Creates a variant from a string

Source§

impl From<Tristate> for Variant

Source§

fn from(t: Tristate) -> Self

Creates a variant from a tristate value

Source§

impl From<Variant> for MutationStart

Source§

fn from(value: Variant) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Variant

Source§

fn from(b: bool) -> Self

Creates a variant from a boolean value

Source§

impl From<i64> for Variant

Source§

fn from(i: i64) -> Self

Creates a variant from an integer value

Source§

impl Into<Hex> for Variant

Source§

fn into(self) -> Hex

Converts the variant into a hexadecimal value, using the Self::to_hex() function.

Source§

impl Into<String> for Variant

Source§

fn into(self) -> String

Converts the variant into a string, using the Self::to_string() function.

Source§

impl Into<Tristate> for Variant

Source§

fn into(self) -> Tristate

Converts the variant into a tristate value, using the Self::to_tristate() function.

Source§

impl Into<bool> for Variant

Source§

fn into(self) -> bool

Converts the variant into a boolean value, using the Self::to_bool() function.

Source§

impl Into<i64> for Variant

Source§

fn into(self) -> i64

Converts the variant into an integer value, using the Self::to_int() function.

Source§

impl Not for Variant

Source§

fn not(self) -> Self::Output

Inverts the variant. If the variant is a boolean, inverts it directly. If the variant is not a boolean, it is converted to a tristate value, then it is inverted, such that the maybe tristate value, retains its properties.

Source§

type Output = Variant

The resulting type after applying the ! operator.
Source§

impl Ord for Variant

Source§

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 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Variant

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 PartialOrd for Variant

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Variant

Source§

impl StructuralPartialEq for Variant

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.