Skip to main content

DatabaseEntry

Trait DatabaseEntry 

Source
pub trait DatabaseEntry:
    Serialize
    + DeserializeOwned
    + for<'de> Deserialize<'de>
    + Clone
    + Debug
    + 'static {
    type Id: EntryId<Entry = Self>;

    const VERSION_NUMBER: u32;

    // Required methods
    fn id(&self) -> Self::Id;
    fn tree(db: &Db) -> Tree;

    // Provided methods
    fn db_check(id: Self::Id) -> Result<bool> { ... }
    fn db_check_version(id: Self::Id) -> Result<Option<u32>, DatabaseError> { ... }
    fn db_create(args: <Self as Createable>::CreateArgs) -> Result<Self>
       where Self: Createable { ... }
    fn db_get(id: Self::Id) -> Result<Option<Self>> { ... }
    fn db_get_all() -> Result<Vec<Self>> { ... }
    fn db_get_batch<I, A>(ids: I) -> Result<Vec<Self>>
       where I: IntoIterator<Item = A>,
             A: Borrow<Self::Id> { ... }
    fn db_merge(&self, into: Self::Id) -> Result<()>
       where Self: Mergeable { ... }
    fn db_patch(&mut self) -> Result<()>
       where Self: Patchable<Self> { ... }
    fn pre_upsert(
        &mut self,
        _cas_tx: &CompareAndSwapTransaction,
    ) -> Result<(), DatabaseError> { ... }
    fn db_upsert(&self) -> Result<()> { ... }
}

Required Associated Constants§

Source

const VERSION_NUMBER: u32

The current version number of the struct, used for updating

Required Associated Types§

Source

type Id: EntryId<Entry = Self>

Required Methods§

Source

fn id(&self) -> Self::Id

Source

fn tree(db: &Db) -> Tree

Provided Methods§

Source

fn db_check(id: Self::Id) -> Result<bool>

Checks if an item exists in the database as lightly as possible

§Errors

Errors if sled fails to read the entry at the id

Source

fn db_check_version(id: Self::Id) -> Result<Option<u32>, DatabaseError>

Source

fn db_create(args: <Self as Createable>::CreateArgs) -> Result<Self>
where Self: Createable,

Creates a new Self in the database using Self::CreateArgs

Source

fn db_get(id: Self::Id) -> Result<Option<Self>>

Gets the entry of Self with the given id

§Errors

Errors if sled fails to retrieve the entry

Source

fn db_get_all() -> Result<Vec<Self>>

Gets all entries of Self in the database

§Errors

Errors if sled fails to retrieve any entry

Source

fn db_get_batch<I, A>(ids: I) -> Result<Vec<Self>>
where I: IntoIterator<Item = A>, A: Borrow<Self::Id>,

Gets all entries of Self in the database with the matching ids

§Errors

Errors if sled fails to retrieve any entry

Source

fn db_merge(&self, into: Self::Id) -> Result<()>
where Self: Mergeable,

Merges self into into in the database.

All items that point to self will be relinked to into and self will be deleted from the database

Source

fn db_patch(&mut self) -> Result<()>
where Self: Patchable<Self>,

Patches or inserts Self into the database

Patching rules depend on how Self implements Patchable<Self>

Source

fn pre_upsert( &mut self, _cas_tx: &CompareAndSwapTransaction, ) -> Result<(), DatabaseError>

Source

fn db_upsert(&self) -> Result<()>

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§