Trait Source

Source
pub trait Source {
    // Required methods
    fn read_entry(
        &mut self,
        offset: u64,
    ) -> Result<(String, Vec<u8>), JasonError>;
    fn write_entry(
        &mut self,
        k: impl AsRef<str>,
        v: impl AsRef<[u8]>,
    ) -> Result<u64, JasonError>;
    fn load_indexes(&mut self) -> Result<HashMap<String, u64>, JasonError>;
    fn index_on(
        &mut self,
        k: impl AsRef<str>,
        indexes: &HashMap<String, u64>,
    ) -> Result<HashMap<Value, BTreeSet<u64>>, JasonError>;
    fn compact(
        &mut self,
        indexes: &HashMap<String, u64>,
    ) -> Result<(), JasonError>;
    fn migrate<Old, New, F>(
        &mut self,
        indexes: &HashMap<String, u64>,
        f: F,
    ) -> Result<(), JasonError>
       where Old: IntoJson + FromJson,
             New: IntoJson + FromJson,
             F: Fn(Old) -> New;
}
Expand description

Represents a backend source for the database.

This handles the database’s low-level storage API. It is currently implemented for:

  • FileSource: A file-based source (default).
  • InMemory: A in-memory source with a simple Vec as its buffer.

Required Methods§

Source

fn read_entry(&mut self, offset: u64) -> Result<(String, Vec<u8>), JasonError>

Reads an entry from the source at the given offset. Returns its key and value.

Source

fn write_entry( &mut self, k: impl AsRef<str>, v: impl AsRef<[u8]>, ) -> Result<u64, JasonError>

Writes an entry to the source with the given key and value. Returns the offset of the new entry.

Source

fn load_indexes(&mut self) -> Result<HashMap<String, u64>, JasonError>

Loads indexes from the source. Returns a map of keys to offsets.

Source

fn index_on( &mut self, k: impl AsRef<str>, indexes: &HashMap<String, u64>, ) -> Result<HashMap<Value, BTreeSet<u64>>, JasonError>

Loads secondary indexes from the source. Returns a map of keys to offsets.

Source

fn compact(&mut self, indexes: &HashMap<String, u64>) -> Result<(), JasonError>

Compacts the database, removing all deleted entries to save space.

Source

fn migrate<Old, New, F>( &mut self, indexes: &HashMap<String, u64>, f: F, ) -> Result<(), JasonError>
where Old: IntoJson + FromJson, New: IntoJson + FromJson, F: Fn(Old) -> New,

Migrates the source from one datatype to another.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§