pub struct MemoryResourceStorage { /* private fields */ }
Expand description

Resource storage in memory.

Used to create and read archives from memory, e.g. for writing tests.

Examples

use flatdata::{MemoryResourceStorage,  Vector};
use flatdata::test::{X, XBuilder};

let storage = MemoryResourceStorage::new("/root/to/my/archive/in/memory");
let builder = XBuilder::new(storage.clone()).expect("failed to create builder");
// Write some data and store it archive, e.g.
let v = Vector::new();
builder.set_data(&v.as_view());

let archive = X::open(storage).expect("failed to open");
// read data
archive.data();

Implementations§

source§

impl MemoryResourceStorage

source

pub fn new<P: Into<PathBuf>>(path: P) -> Arc<Self>

Create an empty memory resource storage at a given virtual path.

Resources will be placed in ephemeral memory with prefix path. A path has to be provided to unify the interface with FileResourceStorage.

Trait Implementations§

source§

impl Debug for MemoryResourceStorage

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl ResourceStorage for MemoryResourceStorage

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. Read more
source§

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

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

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

Open a flatdata resource with given name and schema for reading. Read more
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. Read more
source§

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

Implementation helper for read. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.