pub trait Entity: EntityBase {
type PrimaryKey: KeyType;
// Required methods
fn primary_key(&self) -> Self::PrimaryKey;
fn get<'life0, 'life1, 'async_trait>(
conn: &'life0 mut Self::ConnectionType,
key: &'life1 Self::PrimaryKey,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Option<Self>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn count<'life0, 'async_trait>(
conn: &'life0 mut Self::ConnectionType,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<u32>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn load_all<'life0, 'async_trait>(
conn: &'life0 mut Self::ConnectionType,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Vec<Self>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
Something which can be stored in our database.
It has a primary key, which uniquely identifies it.
Required Associated Types§
Sourcetype PrimaryKey: KeyType
type PrimaryKey: KeyType
Each distinct PrimaryKey uniquely identifies either 0 or 1 instance.
This constraint should be enforced at the DB level.
Required Methods§
Sourcefn primary_key(&self) -> Self::PrimaryKey
fn primary_key(&self) -> Self::PrimaryKey
Get this entity’s primary key.
This must return an owned type, because there are some entities for which only owned primary keys are possible.
However, entities which have primary keys owned within the entity itself should consider also implementing
BorrowPrimaryKey for greater efficiency.
Sourcefn get<'life0, 'life1, 'async_trait>(
conn: &'life0 mut Self::ConnectionType,
key: &'life1 Self::PrimaryKey,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Option<Self>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
conn: &'life0 mut Self::ConnectionType,
key: &'life1 Self::PrimaryKey,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Option<Self>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Get an entity by its primary key.
For entites whose primary key has a distinct borrowed type, it is best to implement this as a direct passthrough:
async fn get(conn: &mut Self::ConnectionType, key: &Self::PrimaryKey) -> CoreCryptoKeystoreResult<Option<Self>> {
Self::get_borrowed(conn, key).await
}Sourcefn count<'life0, 'async_trait>(
conn: &'life0 mut Self::ConnectionType,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<u32>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn count<'life0, 'async_trait>(
conn: &'life0 mut Self::ConnectionType,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<u32>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Count the number of entities of this type in the database.
Sourcefn load_all<'life0, 'async_trait>(
conn: &'life0 mut Self::ConnectionType,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Vec<Self>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn load_all<'life0, 'async_trait>(
conn: &'life0 mut Self::ConnectionType,
) -> Pin<Box<dyn Future<Output = CryptoKeystoreResult<Vec<Self>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Retrieve all entities of this type from the database.
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§
Source§impl Entity for E2eiIntermediateCert
impl Entity for E2eiIntermediateCert
type PrimaryKey = String
Source§impl Entity for MlsPendingMessage
Pending messages have no distinct primary key;
they must always be accessed via MlsPendingMessage::find_all_by_conversation_id and
cleaned up with MlsPendingMessage::delete_by_conversation_id
impl Entity for MlsPendingMessage
Pending messages have no distinct primary key;
they must always be accessed via MlsPendingMessage::find_all_by_conversation_id and
cleaned up with MlsPendingMessage::delete_by_conversation_id