Skip to main content

Width

Trait Width 

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

Source

fn signed(&self, v: i64) -> Option<ConstValue>

A signed value (a decimal literal) in this width; None when it does not fit.

Source

fn unsigned(&self, v: u64) -> Option<ConstValue>

An unsigned value (a hex literal, a size) in this width; None when it does not fit.

Source

fn holds(&self, v: ConstValue) -> bool

Whether v is a value of this width.

Source

fn bounds(&self) -> (String, String)

T::MIN and T::MAX, for a diagnostic.

Source

fn range(&self) -> (i128, i128)

T::MIN and T::MAX, as i128s.

Source

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.

Source

fn compare(&self, op: BinaryOp, a: ConstValue, b: ConstValue) -> Option<bool>

a op b for a comparison; None for an operand of another width.

Source

fn neg(&self, a: ConstValue) -> Option<ConstValue>

-a, checked.

Source

fn not(&self, a: ConstValue) -> Option<ConstValue>

~a.

Source

fn cast(&self, v: ConstValue) -> Option<ConstValue>

v as T, Rust’s conversion: widening is lossless, narrowing is modulo 2ⁿ; None for a bool.

Implementors§