pub struct Index {
pub indexer: Indexer,
/* private fields */
}
Fields§
§indexer: Indexer
Implementations§
Source§impl<'a> Index
impl<'a> Index
Sourcepub fn insert<V>(&mut self, key: &str, value: V)where
V: Serialize + Deserialize<'a>,
pub fn insert<V>(&mut self, key: &str, value: V)where
V: Serialize + Deserialize<'a>,
Inserts a new entry or overrides a previous entry in the index
Sourcepub fn batch(&mut self, f: impl Fn(&mut Batch<'_>) + Sync + Send)
pub fn batch(&mut self, f: impl Fn(&mut Batch<'_>) + Sync + Send)
Batch transaction on the index. you can insert/update/delete multiple entries with one operation by commit the operation with b.commit()
Example
use indexer::{Index, BatchTransaction};
use serde_json::Value;
let mut names_index = Index::new(string_indexer);
names_index.batch(|b| {
b.delete("user.4");
b.insert("user.1", "Kwadwo".to_string());
b.insert("user.2", Value::String("Kwame".to_string()));
b.update("user.3", Value::String("Joseph".to_string()));
b.commit()
});
pub fn get_all_items(&self, f: impl Fn((&String, &Value)) + Sync + Send)
pub fn par_get_all_items(&self, f: impl Fn((&String, &Value)) + Sync + Send)
Sourcepub fn find_where<V>(&self, field: &str, op: Op, value: V) -> QueryResultwhere
V: Serialize + Deserialize<'a>,
pub fn find_where<V>(&self, field: &str, op: Op, value: V) -> QueryResultwhere
V: Serialize + Deserialize<'a>,
Query on an index. by using conditional operators
eq
Equalslt
Less thangt
Greater thanlike
Check for match using Glob style pattern matching
§Example
let query = students_index.find_where("state", Op::EQ, "CA");
println!("Find all students in CA: {:?}", query());
pub fn count(&self) -> usize
👎Deprecated since 0.2.5: Please use the size() instead
pub fn size(&self) -> usize
pub fn get_items(&self) -> Vec<(String, Value)>
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Index
impl<'de> Deserialize<'de> for Index
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Index
impl RefUnwindSafe for Index
impl Send for Index
impl Sync for Index
impl Unpin for Index
impl UnwindSafe for Index
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more