Collection

Struct Collection 

Source
pub struct Collection { /* private fields */ }
Expand description

Group of items in the database

Implementations§

Source§

impl Collection

Source

pub fn get_all<T>(&self) -> Result<Vec<Item<T>>, Error>
where for<'de> T: Deserialize<'de>,

Get all the items in the collection

Source

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

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.

Source

pub fn get_one<T>(&self, id: &Id) -> Result<Item<T>, Error>
where for<'de> T: Deserialize<'de>,

Get one item by its ID

Source

pub fn insert_one<T>(&self, data: &T) -> Result<Id, Error>
where T: Serialize,

Insert one item into the collection

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

Source

pub fn delete_one(&self, id: &Id) -> Result<(), Error>

Delete one item from the collection

Source

pub fn replace_one<T>(&self, item: &Item<T>) -> Result<(), Error>
where T: Serialize,

Overwrite one item in the collection

Source

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

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.

Source

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

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§

Source§

impl Clone for Collection

Source§

fn clone(&self) -> Collection

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Collection

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V