pub struct EntityId { /* private fields */ }Expand description
Identifies one database record: which table it lives in, plus its primary key within that table.
This is the type-erased counterpart to an Entity’s primary key. Equality and hashing cover
both fields, so two entities of different types never collide even if their key bytes agree, and
an id built from a borrowed key compares equal to one built from the owned form.
§Invariant
Entity::TABLE_NAME has to identify the Rust type uniquely. This type only ever compares table
names (Self::matches_type), while the operations which act on the entity behind an id recover
the type by downcasting, so the two notions of identity have to agree. Were two entity types ever
to share a table name, matches_type would answer true for both while the downcast succeeded
for only one — turning the expects which pair the two into panics, and making bulk deletions
silently match nothing. Adding an entity therefore means giving it a table name no other entity
uses.
Implementations§
Source§impl EntityId
impl EntityId
Sourcepub fn from_primary_key<E>(primary_key: E::PrimaryKey) -> Selfwhere
E: Entity,
pub fn from_primary_key<E>(primary_key: E::PrimaryKey) -> Selfwhere
E: Entity,
Build the id of the record of type E with this primary key.
The other constructors all funnel through here.
Sourcepub fn from_entity<E>(entity: &E) -> Selfwhere
E: Entity,
pub fn from_entity<E>(entity: &E) -> Selfwhere
E: Entity,
Build the id of an entity instance.
Note that this asks the entity for its primary key, which for some entities means hashing their contents. Where the id is already available — as a cache key, say — reuse it rather than deriving it again.
Sourcepub fn from_borrowed_primary_key<E>(primary_key: &E::BorrowedPrimaryKey) -> Selfwhere
E: Entity + BorrowPrimaryKey,
pub fn from_borrowed_primary_key<E>(primary_key: &E::BorrowedPrimaryKey) -> Selfwhere
E: Entity + BorrowPrimaryKey,
Build the id of the record of type E with this primary key, in its borrowed form.
Equal to what Self::from_primary_key produces for the owned form of the same key, so the
two are interchangeable for lookups.
Trait Implementations§
impl Eq for EntityId
Auto Trait Implementations§
impl !RefUnwindSafe for EntityId
impl !UnwindSafe for EntityId
impl Freeze for EntityId
impl Send for EntityId
impl Sync for EntityId
impl Unpin for EntityId
impl UnsafeUnpin for EntityId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DynEntityId for T
impl<T> DynEntityId for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more