Gets cached data if state matches, otherwise calls `compute`. Data is automatically serialized/deserialized with `bincode`.
(&self, state: T, compute: fn(&T) -> Result<U, E>)
| 159 | /// |
| 160 | /// Data is automatically serialized/deserialized with `bincode`. |
| 161 | pub fn get_data<T, U, E>(&self, state: T, compute: fn(&T) -> Result<U, E>) -> Result<U, E> |
| 162 | where |
| 163 | T: Hash, |
| 164 | U: Serialize + for<'a> Deserialize<'a>, |
| 165 | { |
| 166 | self.get_data_raw( |
| 167 | &state, |
| 168 | compute, |
| 169 | |_state, data| postcard::to_allocvec(data).ok(), |
| 170 | |_state, data| postcard::from_bytes(&data).ok(), |
| 171 | ) |
| 172 | } |
| 173 | |
| 174 | /// Gets cached data if state matches, otherwise calls `compute`. |
| 175 | /// |