gemini_rust/files/
handle.rs1use snafu::ResultExt;
2use std::sync::Arc;
3
4use super::*;
5use crate::client::GeminiClient;
6
7pub struct FileHandle {
9 inner: super::model::File,
10 client: Arc<GeminiClient>,
11}
12
13impl FileHandle {
14 pub(crate) fn new(client: Arc<GeminiClient>, inner: super::model::File) -> Self {
15 Self { inner, client }
16 }
17
18 pub fn name(&self) -> &str {
19 &self.inner.name
20 }
21
22 pub fn get_file_meta(&self) -> &super::model::File {
24 &self.inner
25 }
26
27 pub async fn delete(self) -> Result<(), (Self, Error)> {
29 match self
30 .client
31 .delete_file(&self.inner.name)
32 .await
33 .context(ClientSnafu)
34 {
35 Ok(_) => Ok(()),
36 Err(e) => Err((self, e)),
37 }
38 }
39
40 pub async fn download(&self) -> Result<Vec<u8>, Error> {
44 self.client
45 .download_file(self.name())
46 .await
47 .context(ClientSnafu)
48 }
49}