MCPcopy Create free account
hub / github.com/ciphermodelabs/ciphercore / to_u128

Method to_u128

ciphercore-base/src/data_values.rs:619–625  ·  view source on GitHub ↗

Converts `self` to a scalar if it is a byte vector, then casts the result to `u128`. # Arguments `st` - scalar type used to interpret `self` # Result Resulting scalar cast to `u128` # Examples ``` # use ciphercore_base::data_values::Value; # use ciphercore_base::data_types::INT32; let v = Value::from_scalar(-123456, INT32).unwrap(); assert_eq!(v.to_u128(INT32).unwrap(), -123456i32 as u128);

(&self, st: ScalarType)

Source from the content-addressed store, hash-verified

617 /// assert_eq!(v.to_u128(INT32).unwrap(), -123456i32 as u128);
618 /// ```
619 pub fn to_u128(&self, st: ScalarType) -> Result<u128> {
620 let v = self.access_bytes(|bytes| vec_u128_from_bytes(bytes, st))?;
621 if v.len() != 1 && (v.len() != 8 || st != BIT) {
622 return Err(runtime_error!("Not a scalar"));
623 }
624 Ok(v[0])
625 }
626
627 /// Converts `self` to a scalar if it is a byte vector, then cast the result to `i128`.
628 ///

Callers 11

to_u8Method · 0.45
to_i8Method · 0.45
to_u16Method · 0.45
to_i16Method · 0.45
to_u32Method · 0.45
to_i32Method · 0.45
to_u64Method · 0.45
to_i64Method · 0.45
to_i128Method · 0.45
test_helperFunction · 0.45

Calls 2

vec_u128_from_bytesFunction · 0.85
access_bytesMethod · 0.80

Tested by 2

test_helperFunction · 0.36