pub enum ConstValue {
Null,
Bool(bool),
Int(i64),
Str(&'static str),
Float(F64),
BitVector(usize, u64),
Expr(&'static Expr),
}
Expand description
Represents a constant value that abstracts various literal types and expressions. This type encapsulates null, boolean, integer, string, floating-point, and expression values, each with respective formatting behavior for debugging and display purposes.
Variants§
Implementations§
Source§impl ConstValue
impl ConstValue
Source§impl ConstValue
impl ConstValue
Sourcepub fn ty(&self) -> Type
pub fn ty(&self) -> Type
Returns the type corresponding to a constant value instance. This function maps each variant of the constant value to its respective type: integer, boolean, string, float, or null, with the expression variant treated as null.
Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Returns an optional boolean extracted from the constant. This function checks if the constant holds a boolean value, and if so, returns it wrapped in Some; otherwise, it returns None.
Sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
Returns the contained integer value if the input represents one. This function checks if the instance holds an integer and, if so, returns it inside an Option; otherwise, it yields None.
Sourcepub fn as_bv(&self) -> Option<u64>
pub fn as_bv(&self) -> Option<u64>
Returns the contained integer value if the input represents one. This function checks if the instance holds an integer and, if so, returns it inside an Option; otherwise, it yields None.
Sourcepub fn as_usize(&self) -> Option<usize>
pub fn as_usize(&self) -> Option<usize>
Converts the integer variant of a constant value into a usize if applicable.
Returns an Option containing the usize representation when the constant is an integer; otherwise, it produces None.
Sourcepub fn as_str(&self) -> Option<&'static str>
pub fn as_str(&self) -> Option<&'static str>
Returns an Option wrapping a static string reference if the constant holds a string value, or None otherwise. This method inspects the constant value and, when it represents a string, provides access to the underlying static string slice, enabling string-specific processing while gracefully handling non-string cases.
Sourcepub fn as_float(&self) -> Option<F64>
pub fn as_float(&self) -> Option<F64>
Returns the floating-point value contained in the constant, if available.
Checks whether the constant is of the float variant, and if so, returns its underlying value wrapped in an Option; otherwise, it produces None.
Sourcepub fn as_expr(&self) -> Option<&'static Expr>
pub fn as_expr(&self) -> Option<&'static Expr>
Returns an optional static reference to an expression if the constant value represents an expression variant. This function checks whether the constant holds an expression and, if so, returns it wrapped in an option; otherwise, it returns None.
Sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
Extracts a floating-point value from a constant if it represents a float. This function checks the internal variant and, when it holds a float, retrieves the underlying f64 value wrapped in an Option; otherwise, it returns None.
Sourcepub fn is_null(&self) -> bool
pub fn is_null(&self) -> bool
Checks whether a constant value is null.
Determines if the constant value represents a null literal and returns true if so, otherwise false.
Sourcepub fn value(&self, len: usize) -> Value
pub fn value(&self, len: usize) -> Value
Converts a constant configuration into a collection value by replicating its underlying data over a specified length.
Matches on the constant variant to determine the appropriate data type and constructs a value by repeatedly inserting the constant element for each index in the specified range. For boolean, integer, string, and float constants, a collection of repeated elements is created, while attempting to convert a null or expression constant results in a panic.
Trait Implementations§
Source§impl Clone for ConstValue
impl Clone for ConstValue
Source§fn clone(&self) -> ConstValue
fn clone(&self) -> ConstValue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for ConstValue
impl Debug for ConstValue
Source§impl Display for ConstValue
impl Display for ConstValue
Source§impl From<&'static Expr> for ConstValue
impl From<&'static Expr> for ConstValue
Source§fn from(original: &'static Expr) -> ConstValue
fn from(original: &'static Expr) -> ConstValue
Source§impl From<&'static str> for ConstValue
impl From<&'static str> for ConstValue
Source§fn from(original: &'static str) -> ConstValue
fn from(original: &'static str) -> ConstValue
Source§impl From<()> for ConstValue
impl From<()> for ConstValue
Source§fn from(original: ()) -> ConstValue
fn from(original: ()) -> ConstValue
Source§impl From<F64> for ConstValue
impl From<F64> for ConstValue
Source§fn from(original: F64) -> ConstValue
fn from(original: F64) -> ConstValue
Source§impl From<bool> for ConstValue
impl From<bool> for ConstValue
Source§fn from(original: bool) -> ConstValue
fn from(original: bool) -> ConstValue
Source§impl From<i64> for ConstValue
impl From<i64> for ConstValue
Source§fn from(original: i64) -> ConstValue
fn from(original: i64) -> ConstValue
Source§impl From<u32> for ConstValue
impl From<u32> for ConstValue
Source§impl From<usize> for ConstValue
impl From<usize> for ConstValue
Source§impl Hash for ConstValue
impl Hash for ConstValue
Source§impl PartialEq for ConstValue
impl PartialEq for ConstValue
impl Copy for ConstValue
impl Eq for ConstValue
impl StructuralPartialEq for ConstValue
Auto Trait Implementations§
impl Freeze for ConstValue
impl RefUnwindSafe for ConstValue
impl Send for ConstValue
impl Sync for ConstValue
impl Unpin for ConstValue
impl UnwindSafe for ConstValue
Blanket Implementations§
Source§impl<T> AllocForAny<T> for T
impl<T> AllocForAny<T> for T
Source§fn galloc(self) -> &'static T
fn galloc(self) -> &'static T
Provides a method to allocate an instance of T
on the heap with a static lifetime.
This implementation of galloc
takes ownership of the T
instance and uses the alloc
function to place it in a location with a static lifetime, presumably managing it in a way that ensures its persistence for the duration of the program.
This can be particularly useful for scenarios where a static lifetime is required, such as when interfacing with systems or patterns that necessitate global state or long-lived data.
Source§fn galloc_mut(self) -> &'static T
fn galloc_mut(self) -> &'static T
Provides a method that moves the instance and returns a reference to it allocated with a static lifetime.
This method utilizes alloc_mut
to perform the allocation, likely involving allocating the resource in a manner that ensures it lives for the entire duration of the application.
These semantics allow the user to safely assume that the reference will not expire during the program’s execution, making it suitable for long-lived data structures or operations that require such guarantees.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more