/// Create a new Value of a given bitwidth out of an initial_val. You do
/// not have to guarantee initial_val satisifies Into<u64>, or bitwidth
/// satisfies Into<usize>.
///
/// # Example:
/// ```
/// use interp::values::*;
/// let val_16_16 = Value::from(16, 16).unwrap();
/// ```
Create a new Value of a given bitwidth out of an initial_val. You do
not have to guarantee initial_val satisifies Into, or bitwidth
satisfies Into.
Create a new Value of a given bitwidth out of an initial_val . You do not have to guarantee initial_val satisifies Into or bitwidth satisfies Into .
pub fn from<T1, T2>(
        initial_val: T1,
        bitwidth: T2,
    ) -> Result<Self, ValueError>
    where
        T1: TryInto<u64>,
        T2: TryInto<usize>,
    {
        let (val, width): (u64, usize) =
            match (initial_val.try_into(), bitwidth.try_into()) {
                (Ok(v1), Ok(v2)) => (v1, v2),
                _ => return Err(ValueError {}),
            };
        let mut vec = BitVec::from_element(val);
        vec.resize(width, false);
        Ok(Value { vec })
    }
pub fn from < T1 , T2 > ( initial_val : T1 , bitwidth : T2 , ) -> Result < Self , ValueError > where T1 : TryInto < u64 > , T2 : TryInto < usize > , { let ( val , width ) : ( u64 , usize ) = match ( initial_val . try_into ( ) , bitwidth . try_into ( ) ) { ( Ok ( v1 ) , Ok ( v2 ) ) => ( v1 , v2 ) , _ => return Err ( ValueError { } ) , } ; let mut vec = BitVec :: from_element ( val ) ; vec . resize ( width , false ) ; Ok ( Value { vec } ) }
Create a new Value of a given bitwidth out of an initial_val.
Create a new Value of a given bitwidth out of an initial_val .
initial_val
T1
bitwidth
T2
example:
None