IndexedJson

Struct IndexedJson 

Source
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>

Source

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.

Source

pub fn path(&self) -> &Path

the base path of the archive

Source

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.

Source

pub async fn reindex(&mut self) -> Result<()>

force rebuild the index

Source

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.

Source

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.

Source

pub fn first(&self) -> Option<IndexEntry>

return the index of the first record in the first file, or none if there are no records

Source

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

Source

pub fn query(&self, query: &Query) -> Result<Set<IndexEntry>>

execute the specified query against the index and return the set of matching entries. You can then retrieve the matching entries using get

Auto Trait Implementations§

§

impl<T> Freeze for IndexedJson<T>

§

impl<T> !RefUnwindSafe for IndexedJson<T>

§

impl<T> Send for IndexedJson<T>
where T: Send,

§

impl<T> Sync for IndexedJson<T>
where T: Sync,

§

impl<T> Unpin for IndexedJson<T>
where T: Unpin,

§

impl<T> !UnwindSafe for IndexedJson<T>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.