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
impl Value
Sourcepub fn from_bytes(bytes: Vec<u8>) -> Self
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
Sourcepub fn from_vector(v: Vec<Value>) -> Self
pub fn from_vector(v: Vec<Value>) -> Self
Source§impl Value
impl Value
Sourcepub fn from_scalar<T: TryInto<u128> + Not<Output = T> + TryInto<u8> + Copy>(
x: T,
st: ScalarType,
) -> Result<Self>
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 typest
- scalar type corresponding tox
§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();
Sourcepub fn from_flattened_array<T: TryInto<u128> + Not<Output = T> + TryInto<u8> + Copy>(
x: &[T],
st: ScalarType,
) -> Result<Value>
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 typest
- scalar type corresponding to the entries ofx
§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();
Sourcepub fn from_flattened_array_u64<T: TryInto<u64> + Not<Output = T> + TryInto<u8> + Copy>(
x: &[T],
st: ScalarType,
) -> Result<Value>
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 typest
- scalar type corresponding to the entries ofx
§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();
Sourcepub fn from_ndarray<T: TryInto<u128> + Not<Output = T> + TryInto<u8> + Copy>(
a: ArrayD<T>,
st: ScalarType,
) -> Result<Value>
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 typest
- scalar type corresponding to the entries ofx
§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();
Sourcepub fn to_u8(&self, st: ScalarType) -> Result<u8>
pub fn to_u8(&self, st: ScalarType) -> Result<u8>
Sourcepub fn to_i8(&self, st: ScalarType) -> Result<i8>
pub fn to_i8(&self, st: ScalarType) -> Result<i8>
Sourcepub fn to_u16(&self, st: ScalarType) -> Result<u16>
pub fn to_u16(&self, st: ScalarType) -> Result<u16>
Sourcepub fn to_i16(&self, st: ScalarType) -> Result<i16>
pub fn to_i16(&self, st: ScalarType) -> Result<i16>
Sourcepub fn to_u32(&self, st: ScalarType) -> Result<u32>
pub fn to_u32(&self, st: ScalarType) -> Result<u32>
Sourcepub fn to_i32(&self, st: ScalarType) -> Result<i32>
pub fn to_i32(&self, st: ScalarType) -> Result<i32>
Sourcepub fn to_u64(&self, st: ScalarType) -> Result<u64>
pub fn to_u64(&self, st: ScalarType) -> Result<u64>
Sourcepub fn to_i64(&self, st: ScalarType) -> Result<i64>
pub fn to_i64(&self, st: ScalarType) -> Result<i64>
Sourcepub fn to_u128(&self, st: ScalarType) -> Result<u128>
pub fn to_u128(&self, st: ScalarType) -> Result<u128>
Sourcepub fn to_i128(&self, st: ScalarType) -> Result<i128>
pub fn to_i128(&self, st: ScalarType) -> Result<i128>
Sourcepub fn to_vector(&self) -> Result<Vec<Value>>
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();
Sourcepub fn to_flattened_array_u8(&self, t: Type) -> Result<Vec<u8>>
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]);
Sourcepub fn to_flattened_array_i8(&self, t: Type) -> Result<Vec<i8>>
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]);
Sourcepub fn to_flattened_array_u16(&self, t: Type) -> Result<Vec<u16>>
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]);
Sourcepub fn to_flattened_array_i16(&self, t: Type) -> Result<Vec<i16>>
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]);
Sourcepub fn to_flattened_array_u32(&self, t: Type) -> Result<Vec<u32>>
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]);
Sourcepub fn to_flattened_array_i32(&self, t: Type) -> Result<Vec<i32>>
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]);
Sourcepub fn to_flattened_array_u64(&self, t: Type) -> Result<Vec<u64>>
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]);
Sourcepub fn to_flattened_array_i64(&self, t: Type) -> Result<Vec<i64>>
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]);
Sourcepub fn to_flattened_array_u128(&self, t: Type) -> Result<Vec<u128>>
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]);
Sourcepub fn to_flattened_array_i128(&self, t: Type) -> Result<Vec<i128>>
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]);
Sourcepub fn check_type(&self, t: Type) -> Result<bool>
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());
Sourcepub fn access_bytes<F, R>(&self, f: F) -> Result<R>
pub fn access_bytes<F, R>(&self, f: F) -> 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();
Sourcepub fn access_vector<F, R>(&self, f: F) -> Result<R>
pub fn access_vector<F, R>(&self, f: F) -> 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();
Sourcepub fn access<FB, FV, R>(&self, f_bytes: FB, f_vector: FV) -> Result<R>
pub fn access<FB, FV, R>(&self, f_bytes: FB, f_vector: FV) -> 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 ifself
corresponds to a byte vectorf_vector
- a closure, that takes a reference to a vector of values, to run ifself
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();
Sourcepub fn zero_of_type(t: Type) -> Value
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());
Sourcepub fn one_of_type(t: Type) -> Result<Value>
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<'de> Deserialize<'de> for Value
impl<'de> Deserialize<'de> for Value
Source§fn deserialize<D>(deserializer: D) -> Result<Value, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Value, D::Error>where
D: Deserializer<'de>,
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
.
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
.
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
.
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
.
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
.
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
.
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
.
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
.
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
.
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
.
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
.
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());
impl Eq for Value
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.