core_crypto_keystore/traits/
entity.rs1use std::borrow::Borrow;
2
3use async_trait::async_trait;
4
5use crate::{
6 CryptoKeystoreResult,
7 traits::{
8 EntityBase, KeyType, OwnedKeyType,
9 primary_key::{BorrowPrimaryKey, PrimaryKey},
10 },
11};
12
13#[cfg_attr(target_family = "wasm", async_trait(?Send))]
17#[cfg_attr(not(target_family = "wasm"), async_trait)]
18pub trait Entity: EntityBase + PrimaryKey {
19 async fn get(conn: &mut Self::ConnectionType, key: &Self::PrimaryKey) -> CryptoKeystoreResult<Option<Self>>;
30
31 async fn count(conn: &mut Self::ConnectionType) -> CryptoKeystoreResult<u32>;
33
34 async fn load_all(conn: &mut Self::ConnectionType) -> CryptoKeystoreResult<Vec<Self>>;
36}
37
38#[cfg_attr(target_family = "wasm", async_trait(?Send))]
39#[cfg_attr(not(target_family = "wasm"), async_trait)]
40pub trait EntityGetBorrowed: Entity + BorrowPrimaryKey {
41 async fn get_borrowed(
43 conn: &mut Self::ConnectionType,
44 key: &Self::BorrowedPrimaryKey,
45 ) -> CryptoKeystoreResult<Option<Self>>
46 where
47 for<'pk> &'pk Self::BorrowedPrimaryKey: KeyType;
48}