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

Method access_bytes

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

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 ``` # use ciphercore_base::data_values::Value; let v = Value::from_bytes(vec![1, 2, 3]); v.access_bytes(|bytes| { assert_eq!(*bytes, vec![1

(&self, f: F)

Source from the content-addressed store, hash-verified

1040 /// }).unwrap();
1041 /// ```
1042 pub fn access_bytes<F, R>(&self, f: F) -> Result<R>
1043 where
1044 F: FnOnce(&[u8]) -> Result<R>,
1045 {
1046 if let ValueBody::Bytes(bytes) = self.body.as_ref() {
1047 f(bytes)
1048 } else {
1049 panic!("Value::access_bytes() on an invalid Value");
1050 }
1051 }
1052
1053 /// Runs a given closure if `self` corresponds to a vector of values, and panic otherwise.
1054 ///

Callers 15

test_prf_output_valueFunction · 0.80
to_u128Method · 0.80
test_get_bytesFunction · 0.80
test_ndarrayFunction · 0.80
test_tupleFunction · 0.80
test_named_tupleFunction · 0.80
test_vectorFunction · 0.80
is_equalMethod · 0.80
generalized_subtractFunction · 0.80
generalized_addFunction · 0.80

Calls

no outgoing calls

Tested by 11

test_prf_output_valueFunction · 0.64
test_get_bytesFunction · 0.64
test_ndarrayFunction · 0.64
test_tupleFunction · 0.64
test_named_tupleFunction · 0.64
test_vectorFunction · 0.64
test_secret_sharingFunction · 0.64
test_low_mc_randomnessFunction · 0.64
test_secret_sharingFunction · 0.64