Struct Store

Source
pub struct Store { /* private fields */ }

Implementations§

Source§

impl Store

Source

pub fn new() -> Self

Same as Store::default()

Source§

impl Store

Source

pub fn seq_next<T: Serialize + 'static>(&self) -> u64

Each object store have a u64 sequential id generator which will increment on each call. Notes:

  • The first seq_next() call will return 1 since is initialize at 0.
  • Also, if the object store does it exists yet, it will create it.
Source

pub fn insert<T: Serialize + 'static>(&self, val: T) -> Result<()>

Insert a new value to the underlying store for this type.

Fails if it cannot call serde_json::to_value

Source

pub fn first<T>( &self, filter: impl Into<Option<FilterGroups>>, ) -> Result<Option<T>>
where T: DeserializeOwned + 'static,

Source

pub fn list<T>(&self, filter: impl Into<Option<FilterGroups>>) -> Result<Vec<T>>
where T: DeserializeOwned + 'static,

List all of the values for a given Type application the Filter

Source

pub fn delete<T>(&self, filter: impl Into<FilterGroups>) -> Result<u64>
where T: DeserializeOwned + 'static,

Source

pub fn update<T, F>( &self, filter: impl Into<FilterGroups>, modifier: F, ) -> Result<u64>
where T: Serialize + DeserializeOwned + 'static, F: Fn(T) -> T,

Update zero or more item in a type store, for a given filter_groups with the modifier function.

Some limitations:

  • It will few clones to keep the API ergonomic convenient. (might try to use Deserialize<'_>)
  • For now, it will stop at first error. Eventually, we might capture the error an continue.
  • Obviously, do not have commit/rollback capability. This is just a mock-store.

Trait Implementations§

Source§

impl Clone for Store

Source§

fn clone(&self) -> Store

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

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

Performs copy-assignment from source. Read more
Source§

impl Default for Store

Source§

fn default() -> Store

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnwindSafe for Store

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.