[][src]Trait flatdata::ResourceStorage

pub trait ResourceStorage {
    fn subdir(&self, dir: &str) -> Rc<dyn ResourceStorage>;
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<Rc<RefCell<dyn Stream>>>; 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> { ... } }

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

fn subdir(&self, dir: &str) -> Rc<dyn ResourceStorage>

Creates a resource storage at a given subdirectory.

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

Returns true if resource exists in the storage.

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.

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

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

Loading content...

Provided methods

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.

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.

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.

Loading content...

Implementors

impl ResourceStorage for FileResourceStorage
[src]

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

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

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

impl ResourceStorage for MemoryResourceStorage
[src]

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

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

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

Loading content...