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 simpleVec
as its buffer.
Required Methods§
Sourcefn read_entry(&mut self, offset: u64) -> Result<(String, Vec<u8>), JasonError>
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.
Sourcefn write_entry(
&mut self,
k: impl AsRef<str>,
v: impl AsRef<[u8]>,
) -> Result<u64, JasonError>
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.
Sourcefn load_indexes(&mut self) -> Result<HashMap<String, u64>, JasonError>
fn load_indexes(&mut self) -> Result<HashMap<String, u64>, JasonError>
Loads indexes from the source. Returns a map of keys to offsets.
Sourcefn index_on(
&mut self,
k: impl AsRef<str>,
indexes: &HashMap<String, u64>,
) -> Result<HashMap<Value, BTreeSet<u64>>, JasonError>
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.
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.