pub struct IndexedJson<T: Indexable + Serialize + for<'a> Deserialize<'a>> { /* private fields */ }Expand description
An indexed json archive
Implementations§
Source§impl<T: Debug + Indexable + Serialize + for<'a> Deserialize<'a>> IndexedJson<T>
impl<T: Debug + Indexable + Serialize + for<'a> Deserialize<'a>> IndexedJson<T>
Sourcepub async fn open(base: impl AsRef<Path>) -> Result<Self>
pub async fn open(base: impl AsRef<Path>) -> Result<Self>
Open an existing indexed json archive, or create a new one. If the index is missing or outdated then it will be rebuilt.
Sourcepub async fn maybe_reindex(&mut self) -> Result<()>
pub async fn maybe_reindex(&mut self) -> Result<()>
Rebuild the index only if necessary. This is called
automatically by open. However if you know, or suspect, the
files have been modified out of band since then, you can call
again and it will check and rebuild the index if they have.
There is no need to do this if you just called append.
Before checking it will also rescan the filesystem. As a result, all open files will be closed. Any new files will be added to the index, and missing files will be removed from it. So if any new files appear or old files disappear the index will be rebuilt.
If the index is damaged you can call reindex, which will
force it to rebuild.
Sourcepub async fn flush(&mut self) -> Result<()>
pub async fn flush(&mut self) -> Result<()>
flush writes to disk. If you call append in batches, you should call this at the end of each batch to make sure your changes are flushed to disk.
Sourcepub async fn append(&mut self, record: &T) -> Result<()>
pub async fn append(&mut self, record: &T) -> Result<()>
append the record to the end of the file corresponding to it’s timestamp and index it.
Sourcepub fn first(&self) -> Option<IndexEntry>
pub fn first(&self) -> Option<IndexEntry>
return the index of the first record in the first file, or none if there are no records
Sourcepub async fn get(
&mut self,
entry: IndexEntry,
) -> Result<Option<(IndexEntry, T)>>
pub async fn get( &mut self, entry: IndexEntry, ) -> Result<Option<(IndexEntry, T)>>
retreive the specified record from the json files. Returns a
pair of the record and the next entry index if there is
one. If None is returned then there were no more entries in
the archive. You can iterate through all the records in the
archive by starting with first and calling get with each
successive record until it returns None