pub enum ConstantValue {
Int(i64),
Float(f64),
UInt(u64),
Bool(bool),
}Expand description
The scalars are stored with the highest precision possible, but they might get reduced during compilation. For constant propagation, casts are always executed before converting back to the larger type to ensure deterministic output.
Variants§
Implementations§
Source§impl ConstantValue
impl ConstantValue
Sourcepub fn try_as_usize(&self) -> Option<usize>
pub fn try_as_usize(&self) -> Option<usize>
Returns the value of the constant as a usize.
It will return None if the constant type is a float or a bool.
Sourcepub fn try_as_u32(&self) -> Option<u32>
pub fn try_as_u32(&self) -> Option<u32>
Returns the value of the scalar as a u32.
It will return None if the scalar type is a float or a bool.
Sourcepub fn as_u32(&self) -> u32
pub fn as_u32(&self) -> u32
Returns the value of the scalar as a u32.
It will panic if the scalar type is a float or a bool.
Sourcepub fn try_as_u64(&self) -> Option<u64>
pub fn try_as_u64(&self) -> Option<u64>
Returns the value of the scalar as a u64.
It will return None if the scalar type is a float or a bool.
Sourcepub fn try_as_i64(&self) -> Option<i64>
pub fn try_as_i64(&self) -> Option<i64>
Returns the value of the scalar as a i64.
It will return None if the scalar type is a float or a bool.
Sourcepub fn try_as_f64(&self) -> Option<f64>
pub fn try_as_f64(&self) -> Option<f64>
Returns the value of the scalar as a f64.
It will return None if the scalar type is an int or a bool.
Sourcepub fn try_as_bool(&self) -> Option<bool>
pub fn try_as_bool(&self) -> Option<bool>
Returns the value of the variable as a bool if it actually is a bool.
Sourcepub fn as_bool(&self) -> bool
pub fn as_bool(&self) -> bool
Returns the value of the variable as a bool.
It will panic if the scalar isn’t a bool.
pub fn is_zero(&self) -> bool
pub fn is_one(&self) -> bool
pub fn cast_to(&self, other: impl Into<Type>) -> ConstantValue
Trait Implementations§
Source§impl Clone for ConstantValue
impl Clone for ConstantValue
Source§fn clone(&self) -> ConstantValue
fn clone(&self) -> ConstantValue
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ConstantValue
impl Debug for ConstantValue
Source§impl<'de> Deserialize<'de> for ConstantValue
impl<'de> Deserialize<'de> for ConstantValue
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for ConstantValue
impl Display for ConstantValue
Source§impl From<bf16> for ConstantValue
impl From<bf16> for ConstantValue
Source§impl From<bool> for ConstantValue
impl From<bool> for ConstantValue
Source§impl From<e2m1> for ConstantValue
impl From<e2m1> for ConstantValue
Source§impl From<e4m3> for ConstantValue
impl From<e4m3> for ConstantValue
Source§impl From<e5m2> for ConstantValue
impl From<e5m2> for ConstantValue
Source§impl From<f16> for ConstantValue
impl From<f16> for ConstantValue
Source§impl From<f32> for ConstantValue
impl From<f32> for ConstantValue
Source§impl From<f64> for ConstantValue
impl From<f64> for ConstantValue
Source§impl From<flex32> for ConstantValue
impl From<flex32> for ConstantValue
Source§impl From<i16> for ConstantValue
impl From<i16> for ConstantValue
Source§impl From<i32> for ConstantValue
impl From<i32> for ConstantValue
Source§impl From<i64> for ConstantValue
impl From<i64> for ConstantValue
Source§impl From<i8> for ConstantValue
impl From<i8> for ConstantValue
Source§impl From<isize> for ConstantValue
impl From<isize> for ConstantValue
Source§impl From<tf32> for ConstantValue
impl From<tf32> for ConstantValue
Source§impl From<u16> for ConstantValue
impl From<u16> for ConstantValue
Source§impl From<u32> for ConstantValue
impl From<u32> for ConstantValue
Source§impl From<u64> for ConstantValue
impl From<u64> for ConstantValue
Source§impl From<u8> for ConstantValue
impl From<u8> for ConstantValue
Source§impl From<ue8m0> for ConstantValue
impl From<ue8m0> for ConstantValue
Source§impl From<usize> for ConstantValue
impl From<usize> for ConstantValue
Source§impl Hash for ConstantValue
impl Hash for ConstantValue
Source§impl Ord for ConstantValue
impl Ord for ConstantValue
Source§impl PartialEq for ConstantValue
impl PartialEq for ConstantValue
Source§impl PartialOrd for ConstantValue
impl PartialOrd for ConstantValue
Source§impl Serialize for ConstantValue
impl Serialize for ConstantValue
Source§impl TypeHash for ConstantValue
impl TypeHash for ConstantValue
impl Copy for ConstantValue
impl Eq for ConstantValue
impl StructuralPartialEq for ConstantValue
Auto Trait Implementations§
impl Freeze for ConstantValue
impl RefUnwindSafe for ConstantValue
impl Send for ConstantValue
impl Sync for ConstantValue
impl Unpin for ConstantValue
impl UnwindSafe for ConstantValue
Blanket Implementations§
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> Comparable<K> for Q
impl<Q, K> Comparable<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.