Skip to main content

StorageService

Trait StorageService 

Source
pub trait StorageService: Send + Sync {
    // Required methods
    fn upload<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        file_name: &'life1 str,
        data: &'life2 [u8],
    ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn download<'life0, 'life1, 'async_trait>(
        &'life0 self,
        file_name: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, StorageError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn target_dir_path(&self) -> String;
    fn validate<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn delete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        file_name: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn list<'life0, 'life1, 'async_trait>(
        &'life0 self,
        prefix: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, StorageError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
}
Expand description

文件存储服务 trait — 平台原语。 负责将文件存储到指定后端(本地文件系统、WebDAV 等)。 与 ShellExecutor 等其他 SDK trait 平级,由 HostApi 持有。

Required Methods§

Source

fn upload<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, file_name: &'life1 str, data: &'life2 [u8], ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

将数据上传到存储后端。 参数:file_name - 相对文件名;data - 文件内容。 返回:成功返回 Ok(()),失败返回 StorageError。

Source

fn download<'life0, 'life1, 'async_trait>( &'life0 self, file_name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

从存储后端下载数据。文件不存在时返回 Ok(None)。 参数:file_name - 相对文件名。 返回:文件内容(文件不存在时为 None),失败返回 StorageError。

Source

fn target_dir_path(&self) -> String

获取存储后端的目标目录路径。

Source

fn validate<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

验证存储配置是否有效(上传+下载测试文件)。

Source

fn delete<'life0, 'life1, 'async_trait>( &'life0 self, file_name: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

从存储后端删除文件。

Source

fn list<'life0, 'life1, 'async_trait>( &'life0 self, prefix: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, StorageError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

列出指定前缀下的所有文件名。

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§