pub trait Width {
// Required methods
fn signed(&self, v: i64) -> Option<ConstValue>;
fn unsigned(&self, v: u64) -> Option<ConstValue>;
fn holds(&self, v: ConstValue) -> bool;
fn bounds(&self) -> (String, String);
fn range(&self) -> (i128, i128);
fn binary(
&self,
op: BinaryOp,
a: ConstValue,
b: ConstValue,
) -> Option<ConstValue>;
fn compare(
&self,
op: BinaryOp,
a: ConstValue,
b: ConstValue,
) -> Option<bool>;
fn neg(&self, a: ConstValue) -> Option<ConstValue>;
fn not(&self, a: ConstValue) -> Option<ConstValue>;
fn cast(&self, v: ConstValue) -> Option<ConstValue>;
}Expand description
One fic width’s Rust integer type, as a value enters it and computes
in it; None for a value of another width.
Required Methods§
Sourcefn signed(&self, v: i64) -> Option<ConstValue>
fn signed(&self, v: i64) -> Option<ConstValue>
A signed value (a decimal literal) in this width; None when it
does not fit.
Sourcefn unsigned(&self, v: u64) -> Option<ConstValue>
fn unsigned(&self, v: u64) -> Option<ConstValue>
An unsigned value (a hex literal, a size) in this width; None
when it does not fit.
Sourcefn holds(&self, v: ConstValue) -> bool
fn holds(&self, v: ConstValue) -> bool
Whether v is a value of this width.
Sourcefn binary(
&self,
op: BinaryOp,
a: ConstValue,
b: ConstValue,
) -> Option<ConstValue>
fn binary( &self, op: BinaryOp, a: ConstValue, b: ConstValue, ) -> Option<ConstValue>
a op b for an arithmetic, bitwise or shift operator, checked;
None on overflow, a shift past the width, division by zero, an
operator of another kind, or an operand of another width.
Sourcefn compare(&self, op: BinaryOp, a: ConstValue, b: ConstValue) -> Option<bool>
fn compare(&self, op: BinaryOp, a: ConstValue, b: ConstValue) -> Option<bool>
a op b for a comparison; None for an operand of another width.
Sourcefn neg(&self, a: ConstValue) -> Option<ConstValue>
fn neg(&self, a: ConstValue) -> Option<ConstValue>
-a, checked.
Sourcefn not(&self, a: ConstValue) -> Option<ConstValue>
fn not(&self, a: ConstValue) -> Option<ConstValue>
~a.
Sourcefn cast(&self, v: ConstValue) -> Option<ConstValue>
fn cast(&self, v: ConstValue) -> Option<ConstValue>
v as T, Rust’s conversion: widening is lossless, narrowing is
modulo 2ⁿ; None for a bool.