Trait StorageBackend

Source
pub trait StorageBackend: Send + Sync {
    // Required methods
    fn create_named(
        &self,
        name: &StoragePath,
    ) -> Result<Box<dyn FileWriter>, StorageError>;
    fn open(
        &self,
        name: &StoragePath,
    ) -> Result<Arc<dyn FileReader>, StorageError>;
    fn list(
        &self,
        parent: &StoragePath,
        cb: &mut dyn FnMut(&StoragePath, StorageFileType),
    ) -> Result<(), StorageError>;
    fn delete(&self, name: &StoragePath) -> Result<(), StorageError>;
    fn delete_recursive(&self, name: &StoragePath) -> Result<(), StorageError>;

    // Provided methods
    fn create(&self) -> Result<Box<dyn FileWriter>, StorageError> { ... }
    fn create_with_prefix(
        &self,
        prefix: &StoragePath,
    ) -> Result<Box<dyn FileWriter>, StorageError> { ... }
    fn delete_if_exists(&self, name: &StoragePath) -> Result<(), StorageError> { ... }
    fn exists(&self, name: &StoragePath) -> Result<bool, StorageError> { ... }
    fn read(&self, name: &StoragePath) -> Result<Arc<FBuf>, StorageError> { ... }
    fn write(
        &self,
        name: &StoragePath,
        content: FBuf,
    ) -> Result<(), StorageError> { ... }
}
Expand description

A storage backend.

Required Methods§

Source

fn create_named( &self, name: &StoragePath, ) -> Result<Box<dyn FileWriter>, StorageError>

Create a new file with the given name, automatically creating any parent directories within name that don’t already exist.

Source

fn open(&self, name: &StoragePath) -> Result<Arc<dyn FileReader>, StorageError>

Opens name for reading.

Source

fn list( &self, parent: &StoragePath, cb: &mut dyn FnMut(&StoragePath, StorageFileType), ) -> Result<(), StorageError>

Calls cb with the name of each of the files under parent. This is a non-recursive list: it does not include files under sub-directories of parent.

Source

fn delete(&self, name: &StoragePath) -> Result<(), StorageError>

Source

fn delete_recursive(&self, name: &StoragePath) -> Result<(), StorageError>

Provided Methods§

Source

fn create(&self) -> Result<Box<dyn FileWriter>, StorageError>

Creates a new persistent file used for writing data. The backend selects a name.

Source

fn create_with_prefix( &self, prefix: &StoragePath, ) -> Result<Box<dyn FileWriter>, StorageError>

Creates a new persistent file used for writing data, giving the file’s name the specified prefix. See also create.

Source

fn delete_if_exists(&self, name: &StoragePath) -> Result<(), StorageError>

Source

fn exists(&self, name: &StoragePath) -> Result<bool, StorageError>

Source

fn read(&self, name: &StoragePath) -> Result<Arc<FBuf>, StorageError>

Reads name and returns its contents. The file name is relative to the base of the storage backend.

Source

fn write(&self, name: &StoragePath, content: FBuf) -> Result<(), StorageError>

Writes content to name, automatically creating any parent directories within name that don’t already exist.

Implementations§

Source§

impl dyn StorageBackend

Source

pub fn new( config: &StorageConfig, options: &StorageOptions, ) -> Result<Arc<Self>, StorageError>

Creates and returns a new backend configured according to config and options.

Implementors§