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)
| 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 | /// |
no outgoing calls