pub trait ResourceStorage: Debug {
    // Required methods
    fn subdir(&self, dir: &str) -> StorageHandle;
    fn exists(&self, resource_name: &str) -> bool;
    fn read_resource(&self, resource_name: &str) -> Result<&[u8], Error>;
    fn create_output_stream(
        &self,
        resource_name: &str
    ) -> Result<Box<dyn Stream>>;

    // Provided methods
    fn read(
        &self,
        resource_name: &str,
        schema: &str
    ) -> Result<&[u8], ResourceStorageError> { ... }
    fn write(
        &self,
        resource_name: &str,
        schema: &str,
        data: &[u8]
    ) -> Result<()> { ... }
    fn read_and_check_schema(
        &self,
        resource_name: &str,
        expected_schema: &str
    ) -> Result<&[u8], ResourceStorageError> { ... }
}
Expand description

Hierarchical Resource Storage

Manages and returns resources corresponding to their keys. Keys can be slash-separated(‘/’). Manages schema for each resource and checks it on query. Resource storage is expected to provide read-write access to resources.

Required Methods§

source

fn subdir(&self, dir: &str) -> StorageHandle

Creates a resource storage at a given subdirectory.

source

fn exists(&self, resource_name: &str) -> bool

Returns true if resource exists in the storage.

source

fn read_resource(&self, resource_name: &str) -> Result<&[u8], Error>

Reads a resource in storage and returns a pointer to its raw data.

This is a low level facility for opening and reading resources. Cf. read for opening flatdata resources and checking the corresponding schema.

source

fn create_output_stream(&self, resource_name: &str) -> Result<Box<dyn Stream>>

Creates a resource with given name and returns an output stream for writing to it.

Provided Methods§

source

fn read( &self, resource_name: &str, schema: &str ) -> Result<&[u8], ResourceStorageError>

Open a flatdata resource with given name and schema for reading.

Also checks if the schema matches the stored schema in the storage. The schema is expected to be stored in the storage as another resource with name {resource_name}.schema.

source

fn write(&self, resource_name: &str, schema: &str, data: &[u8]) -> Result<()>

Writes data of a flatdata resource with given name and schema to storage.

The schema will be stored as another resource under the name {resource_name}.schema.

source

fn read_and_check_schema( &self, resource_name: &str, expected_schema: &str ) -> Result<&[u8], ResourceStorageError>

Implementation helper for read.

Uses the required method read_resource for open the corresponding resource and its schema. It checks the integrity of data by verifying that the size of resource matched the size specified in the header. Also checks that the stored schema matches the provided schema.

Implementors§