| 225 | |
| 226 | impl keyvalue::atomics::Host for WasiKeyValue<'_> { |
| 227 | fn increment( |
| 228 | &mut self, |
| 229 | bucket: Resource<Bucket>, |
| 230 | key: String, |
| 231 | delta: u64, |
| 232 | ) -> Result<u64, Error> { |
| 233 | let bucket = self.table.get_mut(&bucket)?; |
| 234 | let value = bucket |
| 235 | .in_memory_data |
| 236 | .entry(key.clone()) |
| 237 | .or_insert("0".to_string().into_bytes()); |
| 238 | let current_value = String::from_utf8(value.clone()) |
| 239 | .map_err(|e| Error::Other(e.to_string()))? |
| 240 | .parse::<u64>() |
| 241 | .map_err(|e| Error::Other(e.to_string()))?; |
| 242 | let new_value = current_value + delta; |
| 243 | *value = new_value.to_string().into_bytes(); |
| 244 | Ok(new_value) |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | impl keyvalue::batch::Host for WasiKeyValue<'_> { |