| 287 | } |
| 288 | |
| 289 | async fn put(&mut self, name: &str, content: &[u8]) -> io::Result<()> { |
| 290 | let key = Key::for_name(name); |
| 291 | |
| 292 | // There is no information we care about the old entry so we can replace it all in one go |
| 293 | // with a new one. |
| 294 | let entry = Entry::new(content, self.clock.now()?); |
| 295 | |
| 296 | let key = key.serialized(); |
| 297 | match self.storage.set(key, &serde_json::to_string(&entry)?) { |
| 298 | Ok(()) => Ok(()), |
| 299 | Err(e) => Err(io::Error::other(format!( |
| 300 | "Failed to put local storage entry with key {}: {:?}", |
| 301 | key, e |
| 302 | ))), |
| 303 | } |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | /// Factory for web drives. |