[][src]Trait dodo::Storage

pub trait Storage {
    type Read: Read;
    type Write: Write;
    type Iterator: Iterator<Item = Result<Uuid>>;
    fn new(&mut self) -> Result<(Uuid, Self::Write)>;
fn read(&self, entry: Uuid) -> Result<Self::Read>;
fn write(&mut self, entry: Uuid) -> Result<Self::Write>;
fn overwrite(&mut self, entry: Uuid) -> Result<Self::Write>;
fn delete(&mut self, entry: Uuid) -> Result<()>;
fn clear(&mut self) -> Result<()>;
fn iter(&self) -> Result<Self::Iterator>; }

Bytes storage backend.

Each entry is identified by a unique id. Storage implementations may choose to lock entries while they are read or written to.

Associated Types

type Read: Read

Reader.

type Write: Write

Writer.

type Iterator: Iterator<Item = Result<Uuid>>

Iterator.

Loading content...

Required methods

fn new(&mut self) -> Result<(Uuid, Self::Write)>

Create a new entry in this storage, returning his id and a writer.

Returned id is guaranteed to be unique (inside this specific instance of storage, that is).

fn read(&self, entry: Uuid) -> Result<Self::Read>

Provide a reader to an entry, if it exists.

fn write(&mut self, entry: Uuid) -> Result<Self::Write>

Provide a writer to an entry. If it exists, this writer overrides (and truncates) the bytes. If it doesn't exists, a new entry is created.

fn overwrite(&mut self, entry: Uuid) -> Result<Self::Write>

Provide a writer to an entry, only if it exists. This writer override (and truncates) the bytes.

fn delete(&mut self, entry: Uuid) -> Result<()>

Delete an entry.

This does not fail if the entry doesn't exists.

fn clear(&mut self) -> Result<()>

Empties this storage.

Everything in this storage will be deleted. Use at your own risks.

fn iter(&self) -> Result<Self::Iterator>

Provide an iterator listing the entries currently in this storage.

The returned iterator is lazy and doesn't lock anything, meaning returned entries might not even exist when consumed.

Loading content...

Implementors

impl Storage for Directory[src]

type Read = File

type Write = File

type Iterator = Iter

impl Storage for Memory[src]

type Read = BytesReader

type Write = BytesWriter

type Iterator = IntoIter<Result<Uuid>>

Loading content...