[−][src]Trait catwalk::Model
A Model is a representation of data.
A model (as you probably guessed) models data. Specifically, a Model implementation describes: 1. Describes what the data will look like (structure, types, etcetera) 2. The model's name 3. The model's version
Actual instances of implementations will hold the data.
Describing the data
Describing the data structure is easy: add fields to the struct implementing the model.
Required methods
pub fn model_name() -> &'static str
[src]
The name of the model. Each type of model has a name (not to be confused with a model instance's key), this is the used by the PersistenceEngine to determine which Persister to use when storing or retrieving the model.
While not required, it is recommended that the name of the model be the same as the name of the implementing type, but in kebab-case instead of PascalCase.
pub fn model_version() -> &'static Version
[src]
Each model implementation has a version. When the structure of that model changes, the version also needs to change. As of right now, the model implementation must handle converting from an older version to a newer version when deserializing from bytes.
You may notice that this is defined on a Self
level and not a self
level. This is
because all loaded models of a single type should have the same version, and that version
should not change without changes in the code as well.
pub fn get_key(&self) -> &str
[src]
Gets the key for the model instance. As you can probably guess, the key uniquely identifies
a model instance (as opposed to the model_name
which uniquely identifies a model type).