trait TryFromAbstract<T>: Sized {
// Required method
fn try_from_abstract(value: T) -> Result<Self, ConstantEvaluatorError>;
}
Expand description
Trait for conversions of abstract values to concrete types.
Required Methods§
Sourcefn try_from_abstract(value: T) -> Result<Self, ConstantEvaluatorError>
fn try_from_abstract(value: T) -> Result<Self, ConstantEvaluatorError>
Convert an abstract literal value
to Self
.
Since Naga’s AbstractInt
and AbstractFloat
exist to support
WGSL, we follow WGSL’s conversion rules here:
-
WGSL §6.1.2. Conversion Rank says that automatic conversions from
AbstractInt
to an integer type are either lossless or an error. -
WGSL §15.7.6 Floating Point Conversion says that conversions to floating point in constant expressions and override expressions are errors if the value is out of range for the destination type, but rounding is okay.
-
WGSL §17.1.2 i32()/u32() constructors treat AbstractFloat as any other floating point type, following the scalar floating point to integral conversion algorithm (§15.7.6). There is no automatic conversion from AbstractFloat to integer types.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.