pub trait Identifiable: HasTable {
type Id: Hash + Eq;
// Required method
fn id(self) -> Self::Id;
}Expand description
This trait indicates that a struct represents a single row in a database table.
This must be implemented to use associations.
Additionally, implementing this trait allows you to pass your struct to update
(update(&your_struct) is equivalent to
update(YourStruct::table().find(&your_struct.primary_key())).
This trait is usually implemented on a reference to a struct, not on the struct itself. It can be derived.
Required Associated Types§
Required Methods§
Sourcefn id(self) -> Self::Id
fn id(self) -> Self::Id
Returns the identifier for this record.
This takes self by value, not reference.
This is because composite primary keys
are typically stored as multiple fields.
We could not return &(String, String) if each string is a separate field.
Because of Rust’s rules about specifying lifetimes,
this means that Identifiable is usually implemented on references
so that we have a lifetime to use for Id.
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.