Struct Value

Source
pub struct Value { /* private fields */ }
Expand description

A structure that stores pointer to a value that corresponds to an input, output or an intermediate result of a computation.

A value is:

  • Either a vector of bytes (for scalars or arrays);
  • Or a vector of pointers to other values (for vectors, tuples or named tuples).

Overall, a value can be seen as a rooted tree of byte vectors.

Clone trait duplicates the pointer, not the underlying value (see Value::deep_clone for deep cloning).

PartialEq trait performs the deep recursive comparison.

Implementations§

Source§

impl Value

Source

pub fn deep_clone(&self) -> Value

Creates a fully disjoint clone of self via recursive traversal.

§Returns

Clone of self

Source

pub fn deep_hash<H: Hasher>(&self, state: &mut H)

Hashes self via recursive traversal.

§Arguments

state - hasher used for hashing

Source§

impl Value

Source

pub fn from_bytes(bytes: Vec<u8>) -> Self

Constructs a value from a given byte buffer.

Not recommended to be used directly (instead, please use higher-level wrappers such as Value::from_scalar).

§Arguments

bytes - byte vector

§Returns

New value

Source

pub fn from_vector(v: Vec<Value>) -> Self

Constructs a value from a vector of other values.

§Arguments

v - vector of values

§Returns

New value constructed from v

§Examples
let v = Value::from_vector(
    vec![
        Value::from_bytes(vec![1, 2, 3]),
        Value::from_bytes(vec![4, 5, 6]),
        Value::from_vector(vec![])]);
Source§

impl Value

Source

pub fn from_scalar<T: TryInto<u128> + Not<Output = T> + TryInto<u8> + Copy>( x: T, st: ScalarType, ) -> Result<Self>

Constructs a value from a given bit or integer scalar.

§Arguments
  • x - scalar to be converted to a value, can be of any standard integer type
  • st - scalar type corresponding to x
§Returns

New value constructed from x

§Examples
let v = Value::from_scalar(-123456, INT32).unwrap();
v.access_bytes(|bytes| {
    assert_eq!(*bytes, vec![192, 29, 254, 255]);
    Ok(())
}).unwrap();
Source

pub fn from_flattened_array<T: TryInto<u128> + Not<Output = T> + TryInto<u8> + Copy>( x: &[T], st: ScalarType, ) -> Result<Value>

Constructs a value from a flattened bit or integer array.

§Arguments
  • x - array to be converted to a value, can have entries of any standard integer type
  • st - scalar type corresponding to the entries of x
§Returns

New value constructed from x

§Examples
let v = Value::from_flattened_array(&[0, 1, 1, 0, 1, 0, 0, 1], BIT).unwrap();
v.access_bytes(|bytes| {
    assert_eq!(*bytes, vec![150]);
    Ok(())
}).unwrap();
Source

pub fn from_flattened_array_u64<T: TryInto<u64> + Not<Output = T> + TryInto<u8> + Copy>( x: &[T], st: ScalarType, ) -> Result<Value>

Constructs a value from a flattened bit or integer array.

§Arguments
  • x - array to be converted to a value, can have entries of any standard integer type
  • st - scalar type corresponding to the entries of x
§Returns

New value constructed from x

§Examples
let v = Value::from_flattened_array_u64(&[0, 1, 1, 0, 1, 0, 0, 1], BIT).unwrap();
v.access_bytes(|bytes| {
    assert_eq!(*bytes, vec![150]);
    Ok(())
}).unwrap();
Source

pub fn from_ndarray<T: TryInto<u128> + Not<Output = T> + TryInto<u8> + Copy>( a: ArrayD<T>, st: ScalarType, ) -> Result<Value>

Constructs a value from a multi-dimensional bit or integer array.

§Arguments
  • x - array to be converted to a value, can have entries of any standard integer type
  • st - scalar type corresponding to the entries of x
§Returns

New value constructed from x

§Examples
let a = array![[0, 1, 1, 0], [1, 0, 0, 1]].into_dyn();
let v = Value::from_ndarray(a, BIT).unwrap();
v.access_bytes(|bytes| {
    assert_eq!(*bytes, vec![150]);
    Ok(())
}).unwrap();
Source

pub fn to_u8(&self, st: ScalarType) -> Result<u8>

Converts self to a scalar if it is a byte vector, then casts the result to u8.

§Arguments

st - scalar type used to interpret self

§Result

Resulting scalar cast to u8

§Examples
let v = Value::from_scalar(-123456, INT32).unwrap();
assert_eq!(v.to_u8(INT32).unwrap(), -123456i32 as u8);
Source

pub fn to_bit(&self) -> Result<bool>

Converts self to a scalar if it is a byte vector, then casts the result to bool.

§Result

Resulting scalar cast to bool

§Examples
let v = Value::from_scalar(156, UINT8).unwrap();
assert_eq!(v.to_bit().unwrap(), false);
Source

pub fn to_i8(&self, st: ScalarType) -> Result<i8>

Converts self to a scalar if it is a byte vector, then casts the result to i8.

§Arguments

st - scalar type used to interpret self

§Result

Resulting scalar cast to i8

§Examples
let v = Value::from_scalar(-123456, INT32).unwrap();
assert_eq!(v.to_i8(INT32).unwrap(), -123456i32 as i8);
Source

pub fn to_u16(&self, st: ScalarType) -> Result<u16>

Converts self to a scalar if it is a byte vector, then casts the result to u16.

§Arguments

st - scalar type used to interpret self

§Result

Resulting scalar cast to u16

§Examples
let v = Value::from_scalar(-123456, INT32).unwrap();
assert_eq!(v.to_u16(INT32).unwrap(), -123456i32 as u16);
Source

pub fn to_i16(&self, st: ScalarType) -> Result<i16>

Converts self to a scalar if it is a byte vector, then casts the result to i16.

§Arguments

st - scalar type used to interpret self

§Result

Resulting scalar cast to i16

§Examples
let v = Value::from_scalar(-123456, INT32).unwrap();
assert_eq!(v.to_i16(INT32).unwrap(), -123456i32 as i16);
Source

pub fn to_u32(&self, st: ScalarType) -> Result<u32>

Converts self to a scalar if it is a byte vector, then casts the result to u32.

§Arguments

st - scalar type used to interpret self

§Result

Resulting scalar cast to u32

§Examples
let v = Value::from_scalar(-123456, INT32).unwrap();
assert_eq!(v.to_u32(INT32).unwrap(), -123456i32 as u32);
Source

pub fn to_i32(&self, st: ScalarType) -> Result<i32>

Converts self to a scalar if it is a byte vector, then casts the result to i32.

§Arguments

st - scalar type used to interpret self

§Result

Resulting scalar cast to i32

§Examples
let v = Value::from_scalar(-123456, INT32).unwrap();
assert_eq!(v.to_i32(INT32).unwrap(), -123456i32 as i32);
Source

pub fn to_u64(&self, st: ScalarType) -> Result<u64>

Converts self to a scalar if it is a byte vector, then casts the result to u64.

§Arguments

st - scalar type used to interpret self

§Result

Resulting scalar cast to u64

§Examples
let v = Value::from_scalar(-123456, INT32).unwrap();
assert_eq!(v.to_u64(INT32).unwrap(), -123456i32 as u64);
Source

pub fn to_i64(&self, st: ScalarType) -> Result<i64>

Converts self to a scalar if it is a byte vector, then cast the result to i64.

§Arguments

st - scalar type used to interpret self

§Result

Resulting scalar cast to i64

§Examples
let v = Value::from_scalar(-123456, INT32).unwrap();
assert_eq!(v.to_i64(INT32).unwrap(), -123456i32 as i64);
Source

pub fn to_u128(&self, st: ScalarType) -> Result<u128>

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
let v = Value::from_scalar(-123456, INT32).unwrap();
assert_eq!(v.to_u128(INT32).unwrap(), -123456i32 as u128);
Source

pub fn to_i128(&self, st: ScalarType) -> Result<i128>

Converts self to a scalar if it is a byte vector, then cast the result to i128.

§Arguments

st - scalar type used to interpret self

§Result

Resulting scalar cast to i128

§Examples
let v = Value::from_scalar(-123456, INT32).unwrap();
assert_eq!(v.to_i128(INT32).unwrap(), -123456i32 as i128);
Source

pub fn to_vector(&self) -> Result<Vec<Value>>

Converts self to a vector of values or return an error if self is a byte vector.

§Returns

Extracted vector of values

§Examples
let v = Value::from_vector(
    vec![
        Value::from_vector(vec![]),
        Value::from_bytes(vec![1, 2, 3])]);
let vv = v.to_vector().unwrap();
assert_eq!(vv.len(), 2);
vv[0].access_vector(|v| {
    assert_eq!(*v, Vec::<Value>::new());
    Ok(())
}).unwrap();
vv[1].access_bytes(|bytes| {
    assert_eq!(*bytes, vec![1, 2, 3]);
    Ok(())
}).unwrap();
Source

pub fn to_flattened_array_u8(&self, t: Type) -> Result<Vec<u8>>

Converts self to a flattened array if it is a byte vector, then cast the array entries to u8.

§Arguments

t - array type used to interpret self

§Result

Resulting flattened array with entries cast to u8

§Examples
let v = Value::from_flattened_array(&[-123, 123], INT32).unwrap();
let a = v.to_flattened_array_u8(array_type(vec![2], INT32)).unwrap();
assert_eq!(a, vec![-123i32 as u8, 123i32 as u8]);
Source

pub fn to_flattened_array_i8(&self, t: Type) -> Result<Vec<i8>>

Converts self to a flattened array if it is a byte vector, then cast the array entries to i8.

§Arguments

t - array type used to interpret self

§Result

Resulting flattened array with entries cast to i8

§Examples
let v = Value::from_flattened_array(&[-123, 123], INT32).unwrap();
let a = v.to_flattened_array_i8(array_type(vec![2], INT32)).unwrap();
assert_eq!(a, vec![-123i32 as i8, 123i32 as i8]);
Source

pub fn to_flattened_array_u16(&self, t: Type) -> Result<Vec<u16>>

Converts self to a flattened array if it is a byte vector, then cast the array entries to u16.

§Arguments

t - array type used to interpret self

§Result

Resulting flattened array with entries cast to u16

§Examples
let v = Value::from_flattened_array(&[-123, 123], INT32).unwrap();
let a = v.to_flattened_array_u16(array_type(vec![2], INT32)).unwrap();
assert_eq!(a, vec![-123i32 as u16, 123i32 as u16]);
Source

pub fn to_flattened_array_i16(&self, t: Type) -> Result<Vec<i16>>

Converts self to a flattened array if it is a byte vector, then cast the array entries to i16.

§Arguments

t - array type used to interpret self

§Result

Resulting flattened array with entries cast to i16

§Examples
let v = Value::from_flattened_array(&[-123, 123], INT32).unwrap();
let a = v.to_flattened_array_i16(array_type(vec![2], INT32)).unwrap();
assert_eq!(a, vec![-123i32 as i16, 123i32 as i16]);
Source

pub fn to_flattened_array_u32(&self, t: Type) -> Result<Vec<u32>>

Converts self to a flattened array if it is a byte vector, then cast the array entries to u32.

§Arguments

t - array type used to interpret self

§Result

Resulting flattened array with entries cast to u32

§Examples
let v = Value::from_flattened_array(&[-123, 123], INT32).unwrap();
let a = v.to_flattened_array_u32(array_type(vec![2], INT32)).unwrap();
assert_eq!(a, vec![-123i32 as u32, 123i32 as u32]);
Source

pub fn to_flattened_array_i32(&self, t: Type) -> Result<Vec<i32>>

Converts self to a flattened array if it is a byte vector, then cast the array entries to i32.

§Arguments

t - array type used to interpret self

§Result

Resulting flattened array with entries cast to i32

§Examples
let v = Value::from_flattened_array(&[-123, 123], INT32).unwrap();
let a = v.to_flattened_array_i32(array_type(vec![2], INT32)).unwrap();
assert_eq!(a, vec![-123i32, 123i32]);
Source

pub fn to_flattened_array_u64(&self, t: Type) -> Result<Vec<u64>>

Converts self to a flattened array if it is a byte vector, then cast the array entries to u64.

§Arguments

t - array type used to interpret self

§Result

Resulting flattened array with entries cast to u64

§Examples
let v = Value::from_flattened_array(&[-123, 123], INT32).unwrap();
let a = v.to_flattened_array_u64(array_type(vec![2], INT32)).unwrap();
assert_eq!(a, vec![-123i32 as u64, 123i32 as u64]);
Source

pub fn to_flattened_array_i64(&self, t: Type) -> Result<Vec<i64>>

Converts self to a flattened array if it is a byte vector, then cast the array entries to i64.

§Arguments

t - array type used to interpret self

§Result

Resulting flattened array with entries cast to i64

§Examples
let v = Value::from_flattened_array(&[-123, 123], INT32).unwrap();
let a = v.to_flattened_array_i64(array_type(vec![2], INT32)).unwrap();
assert_eq!(a, vec![-123, 123]);
Source

pub fn to_flattened_array_u128(&self, t: Type) -> Result<Vec<u128>>

Converts self to a flattened array if it is a byte vector, then cast the array entries to u128.

§Arguments

t - array type used to interpret self

§Result

Resulting flattened array with entries cast to u128

§Examples
let v = Value::from_flattened_array(&[-123, 123], INT32).unwrap();
let a = v.to_flattened_array_u128(array_type(vec![2], INT32)).unwrap();
assert_eq!(a, vec![-123i32 as u128, 123i32 as u128]);
Source

pub fn to_flattened_array_i128(&self, t: Type) -> Result<Vec<i128>>

Converts self to a flattened array if it is a byte vector, then cast the array entries to i128.

§Arguments

t - array type used to interpret self

§Result

Resulting flattened array with entries cast to i128

§Examples
let v = Value::from_flattened_array(&[-123, 123], INT32).unwrap();
let a = v.to_flattened_array_i128(array_type(vec![2], INT32)).unwrap();
assert_eq!(a, vec![-123, 123]);
Source

pub fn check_type(&self, t: Type) -> Result<bool>

Checks if self is a valid value for a given type.

§Arguments

t - a type to check a value against

§Returns

true if self is a valid value of type t, false otherwise

§Examples
assert!(Value::from_bytes(vec![1, 2, 3, 4]).check_type(scalar_type(INT32)).unwrap());
assert!(Value::from_bytes(vec![1, 2, 3, 4]).check_type(scalar_type(UINT32)).unwrap());
assert!(Value::from_bytes(vec![1, 2, 3, 4]).check_type(array_type(vec![2, 2], UINT8)).unwrap());
assert!(Value::from_bytes(vec![1, 2, 3, 4]).check_type(array_type(vec![4, 8], BIT)).unwrap());
assert!(!Value::from_bytes(vec![1, 2, 3, 4]).check_type(array_type(vec![3, 5], BIT)).unwrap());
assert!(!Value::from_bytes(vec![1, 2, 3, 4]).check_type(array_type(vec![5], UINT8)).unwrap());
assert!(!Value::from_bytes(vec![1, 2, 3, 4]).check_type(array_type(vec![3], UINT16)).unwrap());
assert!(!Value::from_bytes(vec![1, 2, 3, 4]).check_type(scalar_type(UINT64)).unwrap());
Source

pub fn access_bytes<F, R>(&self, f: F) -> Result<R>
where F: FnOnce(&[u8]) -> Result<R>,

Runs a given closure if self corresponds to a byte vector, and panic otherwise.

§Arguments

f - a closure, that takes a reference to a slice of bytes, to run

§Returns

Return value of f

§Panics

Panics if self is a vector of values.

§Examples

let v = Value::from_bytes(vec![1, 2, 3]);
v.access_bytes(|bytes| {
    assert_eq!(*bytes, vec![1, 2, 3]);
    Ok(())
}).unwrap();
Source

pub fn access_vector<F, R>(&self, f: F) -> Result<R>
where F: FnOnce(&Vec<Value>) -> Result<R>,

Runs a given closure if self corresponds to a vector of values, and panic otherwise.

§Arguments

f - a closure, that takes a reference to a vector of values, to run

§Returns

Return value of f

§Panics

Panics if self is a byte vector.

§Examples

let v = Value::from_vector(vec![]);
v.access_vector(|vector| {
    assert!(vector.is_empty());
    Ok(())
}).unwrap();
Source

pub fn access<FB, FV, R>(&self, f_bytes: FB, f_vector: FV) -> Result<R>
where FB: FnOnce(&[u8]) -> Result<R>, FV: FnOnce(&Vec<Value>) -> Result<R>,

Runs one closure if self corresponds to a byte vector, and another closure if self corresponds to a vector of values.

§Arguments
  • f_bytes - a closure, that takes a reference to a slice of bytes, to run if self corresponds to a byte vector
  • f_vector - a closure, that takes a reference to a vector of values, to run if self corresponds to a vector of values
§Returns

Return value of the called closure

§Examples

let v1 = Value::from_vector(vec![]);
let v2 = Value::from_bytes(vec![1, 2, 3]);
v1.access(|bytes| {
    assert!(false);
    Ok(())
},
|vector| {
    assert!(vector.is_empty());
    Ok(())
}).unwrap();
v2.access(|bytes| {
    assert_eq!(*bytes, vec![1, 2, 3]);
    Ok(())
},
|vector| {
    assert!(false);
    Ok(())
}).unwrap();
Source

pub fn zero_of_type(t: Type) -> Value

Generates a value of a given type with all-zero bytes.

§Arguments

t - the type of a new value

§Returns

“Zero” value of type t

§Examples
let v = Value::zero_of_type(array_type(vec![2, 2], INT32));
let a = ToNdarray::<u8>::to_ndarray(&v,array_type(vec![2, 2], INT32) ).unwrap();
assert_eq!(a, array![[0, 0], [0, 0]].into_dyn());
Source

pub fn one_of_type(t: Type) -> Result<Value>

Generates a value of a given type with all-one bytes.

§Arguments

t - the type of a new value

§Returns

“One” value of type t

§Examples
let v = Value::one_of_type(array_type(vec![2, 2], INT32)).unwrap();
let a = ToNdarray::<u8>::to_ndarray(&v,array_type(vec![2, 2], INT32) ).unwrap();
assert_eq!(a, array![[1, 1], [1, 1]].into_dyn());

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Value

Source§

fn deserialize<D>(deserializer: D) -> Result<Value, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Value

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Value

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl ToNdarray<bool> for Value

Converts self to a multi-dimensional array if it is a byte vector, then cast the array entries to u64.

§Arguments

t - array type used to interpret self

§Result

Resulting multi-dimensional array with entries cast to u64

§Examples

let a = array![[false, true], [true, false]].into_dyn();
let v = Value::from_ndarray(a.clone(), BIT).unwrap();
let converted = ToNdarray::<bool>::to_ndarray(&v,array_type(vec![2, 2], BIT)).unwrap();
assert_eq!(converted, a);
Source§

impl ToNdarray<i128> for Value

Converts self to a multi-dimensional array if it is a byte vector, then cast the array entries to i128.

§Arguments

t - array type used to interpret self

§Result

Resulting multi-dimensional array with entries cast to i128

§Examples

let a = array![[-123, 123], [-456, 456]].into_dyn();
let v = Value::from_ndarray(a, INT32).unwrap();
let a = ToNdarray::<i128>::to_ndarray(&v,array_type(vec![2, 2], INT32)).unwrap();
assert_eq!(a, array![[-123i32 as i128, 123i32 as i128], [-456i32 as i128, 456i32 as i128]].into_dyn());
Source§

impl ToNdarray<i16> for Value

Converts self to a multi-dimensional array if it is a byte vector, then cast the array entries to i16.

§Arguments

t - array type used to interpret self

§Result

Resulting multi-dimensional array with entries cast to i16

§Examples

let a = array![[-123, 123], [-456, 456]].into_dyn();
let v = Value::from_ndarray(a, INT32).unwrap();
let a = ToNdarray::<i16>::to_ndarray(&v,array_type(vec![2, 2], INT32)).unwrap();
assert_eq!(a, array![[-123i32 as i16, 123i32 as i16], [-456i32 as i16, 456i32 as i16]].into_dyn());
Source§

impl ToNdarray<i32> for Value

Converts self to a multi-dimensional array if it is a byte vector, then cast the array entries to i32.

§Arguments

t - array type used to interpret self

§Result

Resulting multi-dimensional array with entries cast to i32

§Examples

let a = array![[-123, 123], [-456, 456]].into_dyn();
let v = Value::from_ndarray(a, INT32).unwrap();
let a = ToNdarray::<i32>::to_ndarray(&v,array_type(vec![2, 2], INT32)).unwrap();
assert_eq!(a, array![[-123i32, 123i32], [-456i32, 456i32]].into_dyn());
Source§

impl ToNdarray<i64> for Value

Converts self to a multi-dimensional array if it is a byte vector, then cast the array entries to i64.

§Arguments

t - array type used to interpret self

§Result

Resulting multi-dimensional array with entries cast to i64

§Examples

let a = array![[-123, 123], [-456, 456]].into_dyn();
let v = Value::from_ndarray(a, INT32).unwrap();
let a = ToNdarray::<i64>::to_ndarray(&v,array_type(vec![2, 2], INT32)).unwrap();
assert_eq!(a, array![[-123i32 as i64, 123i32 as i64], [-456i32 as i64, 456i32 as i64]].into_dyn());
Source§

impl ToNdarray<i8> for Value

Converts self to a multi-dimensional array if it is a byte vector, then cast the array entries to i8.

§Arguments

t - array type used to interpret self

§Result

Resulting multi-dimensional array with entries cast to i8

§Examples

let a = array![[-123, 123], [-456, 456]].into_dyn();
let v = Value::from_ndarray(a, INT32).unwrap();
let a = ToNdarray::<i8>::to_ndarray(&v,array_type(vec![2, 2], INT32)).unwrap();
assert_eq!(a, array![[-123i32 as i8, 123i32 as i8], [-456i32 as i8, 456i32 as i8]].into_dyn());
Source§

impl ToNdarray<u128> for Value

Converts self to a multi-dimensional array if it is a byte vector, then cast the array entries to u128.

§Arguments

t - array type used to interpret self

§Result

Resulting multi-dimensional array with entries cast to u64

§Examples

let a = array![[-123, 123], [-456, 456]].into_dyn();
let v = Value::from_ndarray(a, INT32).unwrap();
let a = ToNdarray::<u128>::to_ndarray(&v,array_type(vec![2, 2], INT32)).unwrap();
assert_eq!(a, array![[-123i32 as u128, 123i32 as u128], [-456i32 as u128, 456i32 as u128]].into_dyn());
Source§

impl ToNdarray<u16> for Value

Converts self to a multi-dimensional array if it is a byte vector, then cast the array entries to u16.

§Arguments

t - array type used to interpret self

§Result

Resulting multi-dimensional array with entries cast to u16

§Examples

let a = array![[-123, 123], [-456, 456]].into_dyn();
let v = Value::from_ndarray(a, INT32).unwrap();
let a = ToNdarray::<u16>::to_ndarray(&v,array_type(vec![2, 2], INT32)).unwrap();
assert_eq!(a, array![[-123i32 as u16, 123i32 as u16], [-456i32 as u16, 456i32 as u16]].into_dyn());
Source§

impl ToNdarray<u32> for Value

Converts self to a multi-dimensional array if it is a byte vector, then cast the array entries to u32.

§Arguments

t - array type used to interpret self

§Result

Resulting multi-dimensional array with entries cast to u32

§Examples

let a = array![[-123, 123], [-456, 456]].into_dyn();
let v = Value::from_ndarray(a, INT32).unwrap();
let a = ToNdarray::<u32>::to_ndarray(&v,array_type(vec![2, 2], INT32)).unwrap();
assert_eq!(a, array![[-123i32 as u32, 123i32 as u32], [-456i32 as u32, 456i32 as u32]].into_dyn());
Source§

impl ToNdarray<u64> for Value

Converts self to a multi-dimensional array if it is a byte vector, then cast the array entries to u64.

§Arguments

t - array type used to interpret self

§Result

Resulting multi-dimensional array with entries cast to u64

§Examples

let a = array![[-123, 123], [-456, 456]].into_dyn();
let v = Value::from_ndarray(a, INT32).unwrap();
let a = ToNdarray::<u64>::to_ndarray(&v,array_type(vec![2, 2], INT32)).unwrap();
assert_eq!(a, array![[-123i32 as u64, 123i32 as u64], [-456i32 as u64, 456i32 as u64]].into_dyn());
Source§

impl ToNdarray<u8> for Value

Converts self to a multi-dimensional array if it is a byte vector, then cast the array entries to u8.

§Arguments

t - array type used to interpret self

§Result

Resulting multi-dimensional array with entries cast to u8

§Examples

let a = array![[-123, 123], [-456, 456]].into_dyn();
let v = Value::from_ndarray(a, INT32).unwrap();
let a = ToNdarray::<u8>::to_ndarray(&v, array_type(vec![2, 2], INT32)).unwrap();
assert_eq!(a, array![[-123i32 as u8, 123i32 as u8], [-456i32 as u8, 456i32 as u8]].into_dyn());
Source§

impl Eq for Value

Source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnwindSafe for Value

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,