[][src]Struct ipjdb::Collection

pub struct Collection { /* fields omitted */ }

Group of items in the database

Methods

impl Collection[src]

pub fn get_all<T>(&self) -> Result<Vec<Item<T>>, DbError> where
    T: Deserialize<'de>, 
[src]

Get all the items in the collection

pub fn find_many<T, F>(&self, f: F) -> Result<Vec<Item<T>>, DbError> where
    T: Deserialize<'de>,
    F: Fn(&Item<T>) -> bool
[src]

Get a subset of the items in the collection

Items are filtered by the function f, which is passed an Item and should return true to include that Item in the results, or false to exclude it from the results.

pub fn get_one<T>(&self, id: &Id) -> Result<Item<T>, DbError> where
    T: Deserialize<'de>, 
[src]

Get one item by its ID

pub fn insert_one<T>(&self, data: &T) -> Result<Id, DbError> where
    T: Serialize
[src]

Insert one item into the collection

A unique ID will be generated for the item and returned.

pub fn delete_one(&self, id: &Id) -> Result<(), DbError>[src]

Delete one item from the collection

pub fn replace_one<T>(&self, item: &Item<T>) -> Result<(), DbError> where
    T: Serialize
[src]

Overwrite one item in the collection

pub fn update_by_id<T, U>(&self, id: &Id, u: U) -> Result<(), DbError> where
    T: Deserialize<'de> + Serialize,
    U: Fn(&mut Item<T>), 
[src]

Find an item by its ID and update it

If the item is found, the function u will be called with that item. The function can modify the data as needed, and the new item will be written to the collection. Note that the ID cannot be modified.

pub fn update_many<T, F, U>(&self, f: F, u: U) -> Result<(), DbError> where
    T: Deserialize<'de> + Serialize,
    F: Fn(&Item<T>) -> bool,
    U: Fn(&mut Item<T>), 
[src]

Update a subset of the items in the collection

For each item in the collection the function f is called with that item. The function should return true to update the item or false to leave it unmodified. For each item where f returned true, the function u is called to update the item. The function can modify the data as needed, and the new item will be written to the collection. Note that the ID cannot be modified.

Trait Implementations

impl Debug for Collection[src]

Auto Trait Implementations

impl Send for Collection

impl Sync for Collection

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]