Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure proper documentation for the Resource enum (n-01) #2640

Merged
merged 2 commits into from
Nov 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions crates/dojo/core/src/world/resource.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,28 @@ use starknet::ContractAddress;
/// of re-computing the descriptor each time, which involves several poseidon hash
/// operations.
///
/// Namespaced resources: Those resources are scoped by a namespace, which
/// defines a logical separation of resources. Namespaced resources are Model, Event and Contract.
///
/// - World: The world itself, identified by the selector 0.
///
/// - Namespace: ByteArray
/// Namespace is a unique resource type, identified by a `ByteArray`, to scope models, events and
/// contracts.
/// The poseidon hash of the serialized `ByteArray` is used as the namespace hash.
///
/// - Model: (ContractAddress, NamespaceHash)
/// A model defines data that can be stored in the world's storage.
///
/// - Event: (ContractAddress, NamespaceHash)
/// An event is never stored in the world's storage, but it's emitted by the world to be consumed by
/// off-chain components.
///
/// - Contract: (ContractAddress, NamespaceHash)
/// - Namespace: ByteArray
/// - World: The world itself, identified by the selector 0.
/// - Unregistered: The unregistered state.
/// A contract defines user logic to interact with the world's data (models) and to emit events.
///
/// - Unregistered: The unregistered state, required to ensure the security of the world
/// to not have operations done on non-existent resources.
#[derive(Drop, starknet::Store, Serde, Default, Debug)]
pub enum Resource {
Model: (ContractAddress, felt252),
Expand All @@ -26,6 +43,7 @@ pub enum Resource {

#[generate_trait]
pub impl ResourceIsNoneImpl of ResourceIsNoneTrait {
/// Returns true if the resource is unregistered, false otherwise.
fn is_unregistered(self: @Resource) -> bool {
match self {
Resource::Unregistered => true,
Expand Down
Loading