gemini_rust/cache/
handle.rs1use snafu::ResultExt;
2use std::sync::Arc;
3
4use super::model::*;
5use super::*;
6use crate::client::GeminiClient;
7
8#[derive(Clone)]
13pub struct CachedContentHandle {
14 pub name: String,
16 client: Arc<GeminiClient>,
17}
18
19impl CachedContentHandle {
20 pub(crate) fn new(name: String, client: Arc<GeminiClient>) -> Self {
22 Self { name, client }
23 }
24
25 pub fn name(&self) -> &str {
27 &self.name
28 }
29
30 pub async fn get(&self) -> Result<CachedContent, Error> {
32 self.client
33 .get_cached_content(&self.name)
34 .await
35 .map_err(Box::new)
36 .context(ClientSnafu)
37 }
38
39 pub async fn update(&self, expiration: CacheExpirationRequest) -> Result<CachedContent, Error> {
41 self.client
42 .update_cached_content(&self.name, expiration)
43 .await
44 .map_err(Box::new)
45 .context(ClientSnafu)
46 }
47
48 #[allow(clippy::result_large_err)]
50 pub async fn delete(self) -> Result<(), (Self, Error)> {
51 match self
52 .client
53 .delete_cached_content(&self.name)
54 .await
55 .map_err(Box::new)
56 .context(ClientSnafu)
57 {
58 Ok(response) => Ok(response),
59 Err(e) => Err((self, e)),
60 }
61 }
62}