[−][src]Trait domain_patterns::models::Entity
A trait that defines an Entity
, which is any object with a unique and globally persistent identity.
The generic type K
should match the same type as the internal globally unique id used for the entity.
Be careful when choosing what to return here. The result of id()
will be used as the primary key
for the entity when communicating with a database via a repository.
Example
use domain_patterns::models::Entity; struct User { id: uuid::Uuid, email: String, password: String, } impl Entity for User { fn id(&self) -> String { self.id.to_string() } } impl std::cmp::PartialEq for User { fn eq(&self, other: &Self) -> bool { &self.id() == &other.id() } }
Required methods
fn id(&self) -> String
id should be the entities globally unique id. It doesn't matter what it is internally as long as that thing can be returned as a string (implements Display from std)