Skip to main content

remote_fs/
traits.rs

1use std::path::Path;
2
3use async_trait::async_trait;
4
5use crate::error::Result;
6use crate::types::{FileEntry, FileMeta};
7
8/// Unified async remote file system operations.
9#[async_trait]
10pub trait RemoteFileSystem: Send {
11    /// Connect to the remote server.
12    async fn connect(&mut self) -> Result<()>;
13
14    /// Disconnect from the remote server.
15    async fn disconnect(&mut self) -> Result<()>;
16
17    /// Whether the client is currently connected.
18    fn is_connected(&self) -> bool;
19
20    /// List entries under `path`.
21    async fn list(&mut self, path: &str) -> Result<Vec<FileEntry>>;
22
23    /// Get metadata for `path`.
24    async fn metadata(&mut self, path: &str) -> Result<FileMeta>;
25
26    /// Check whether `path` exists.
27    async fn exists(&mut self, path: &str) -> Result<bool>;
28
29    /// Create a directory at `path`.
30    async fn mkdir(&mut self, path: &str) -> Result<()>;
31
32    /// Create directories recursively.
33    async fn mkdir_all(&mut self, path: &str) -> Result<()>;
34
35    /// Remove an empty directory.
36    async fn rmdir(&mut self, path: &str) -> Result<()>;
37
38    /// Remove a file.
39    async fn remove_file(&mut self, path: &str) -> Result<()>;
40
41    /// Remove a file or directory recursively.
42    async fn remove(&mut self, path: &str) -> Result<()>;
43
44    /// Rename / move a path.
45    async fn rename(&mut self, from: &str, to: &str) -> Result<()>;
46
47    /// Read entire file into memory.
48    async fn read(&mut self, path: &str) -> Result<Vec<u8>>;
49
50    /// Write entire file from memory.
51    async fn write(&mut self, path: &str, data: &[u8]) -> Result<()>;
52
53    /// Download remote file to local path.
54    async fn download(&mut self, remote: &str, local: &Path) -> Result<()>;
55
56    /// Upload local file to remote path.
57    async fn upload(&mut self, local: &Path, remote: &str) -> Result<()>;
58}