Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

Model

The Model trait.

It provides a standardized way to interact with models.

Fully qualified path: dojo::model::model::Model

pub trait Model<M>

Trait functions

keys

Parses the key from the given model, where K is a type containing the keys of the model.

Fully qualified path: dojo::model::model::Model::keys

fn keys<K, +KeyParser<M, K>>(self: @M) -> K

entity_id

Returns the entity id of the model.

Fully qualified path: dojo::model::model::Model::entity_id

fn entity_id(self: @M) -> felt252

serialized_keys

Returns the keys of the model.

Fully qualified path: dojo::model::model::Model::serialized_keys

fn serialized_keys(self: @M) -> Span<felt252>

serialized_values

Returns the values of the model.

Fully qualified path: dojo::model::model::Model::serialized_values

fn serialized_values(self: @M) -> Span<felt252>

from_serialized

Constructs a model from the given keys and values.

Fully qualified path: dojo::model::model::Model::from_serialized

fn from_serialized(keys: Span<felt252>, values: Span<felt252>) -> Option<M>

from_serialized_subset

Contrutcs a model subset (member or schema) from its serialized value.

Fully qualified path: dojo::model::model::Model::from_serialized_subset

fn from_serialized_subset<T, +Serde<T>, +DojoStore<T>>(value: Span<felt252>) -> Option<T>

serialized_subset

Returns the serialized value of a model subset (member or schema).

Fully qualified path: dojo::model::model::Model::serialized_subset

fn serialized_subset<T, +Serde<T>, +DojoStore<T>>(value: @T) -> Span<felt252>

name

Returns the name of the model. (TODO: internalizing the name_hash could reduce poseidon costs).

Fully qualified path: dojo::model::model::Model::name

fn name() -> ByteArray

schema

Returns the schema of the model.

Fully qualified path: dojo::model::model::Model::schema

fn schema() -> Struct

layout

Returns the memory layout of the model.

Fully qualified path: dojo::model::model::Model::layout

fn layout() -> Layout

field_layout

Returns the layout of a field in the model.

Fully qualified path: dojo::model::model::Model::field_layout

fn field_layout(field_selector: felt252) -> Option<Layout>

use_legacy_storage

Indicates if the model uses the legacy storage (true), or the new one (false).

Fully qualified path: dojo::model::model::Model::use_legacy_storage

fn use_legacy_storage() -> bool

unpacked_size

Returns the unpacked size of the model. Only applicable for fixed size models.

Fully qualified path: dojo::model::model::Model::unpacked_size

fn unpacked_size() -> Option<u32>

packed_size

Returns the packed size of the model. Only applicable for fixed size models.

Fully qualified path: dojo::model::model::Model::packed_size

fn packed_size() -> Option<u32>

instance_layout

Returns the instance selector of the model.

Fully qualified path: dojo::model::model::Model::instance_layout

fn instance_layout(self: @M) -> Layout

definition

Returns the definition of the model.

Fully qualified path: dojo::model::model::Model::definition

fn definition() -> ModelDef

selector

Returns the selector of the model computed for the given namespace hash.

Fully qualified path: dojo::model::model::Model::selector

fn selector(namespace_hash: felt252) -> felt252

ptr_from_keys

Returns the pointer to the model from the keys.

Fully qualified path: dojo::model::model::Model::ptr_from_keys

fn ptr_from_keys<K, +Serde<K>, +Drop<K>>(keys: K) -> ModelPtr<M>

ptr_from_serialized_keys

Returns the pointer to the model from the serialised keys.

Fully qualified path: dojo::model::model::Model::ptr_from_serialized_keys

fn ptr_from_serialized_keys(keys: Span<felt252>) -> ModelPtr<M>

ptr_from_id

Returns the pointer to the model from the entity id.

Fully qualified path: dojo::model::model::Model::ptr_from_id

fn ptr_from_id(entity_id: felt252) -> ModelPtr<M>

ptrs_from_keys

Returns the pointers to models from the keys.

Fully qualified path: dojo::model::model::Model::ptrs_from_keys

fn ptrs_from_keys<K, +Serde<K>, +Drop<K>>(keys: Span<K>) -> Span<ModelPtr<M>>

ptrs_from_serialized_keys

Returns the pointers to models from the serialised keys.

Fully qualified path: dojo::model::model::Model::ptrs_from_serialized_keys

fn ptrs_from_serialized_keys(keys: Span<Span<felt252>>) -> Span<ModelPtr<M>>

ptrs_from_ids

Returns the pointers to models from the entity ids.

Fully qualified path: dojo::model::model::Model::ptrs_from_ids

fn ptrs_from_ids(entity_ids: Span<felt252>) -> Span<ModelPtr<M>>

ptr

Returns the ptr of the model.

Fully qualified path: dojo::model::model::Model::ptr

fn ptr(self: @M) -> ModelPtr<M>