From ec7c12968b006784f5bad4f2150991aa4ee92038 Mon Sep 17 00:00:00 2001 From: Tristan <122918260+TAdev0@users.noreply.github.com> Date: Fri, 10 Jan 2025 10:32:13 +0100 Subject: [PATCH] Core Lib Documentation:`storage_base` module (#7039) Co-authored-by: enitrat --- .../src/starknet/storage/storage_base.cairo | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/corelib/src/starknet/storage/storage_base.cairo b/corelib/src/starknet/storage/storage_base.cairo index 6dfbd296be2..b7dcf8c52ff 100644 --- a/corelib/src/starknet/storage/storage_base.cairo +++ b/corelib/src/starknet/storage/storage_base.cairo @@ -1,7 +1,16 @@ +//! Core abstractions for contract storage management. +//! +//! This module provides the types and traits for handling contract storage internally +//! within the Cairo core library. Most developers should not need to implement these traits +//! directly, as they are primarily used by the storage system implementation. +//! +//! If you're writing a regular Starknet contract, you should use the high-level storage +//! traits and types, interacting with the members of the storage struct directly. + use super::{Mutable, StorageAsPath, StoragePath, StoragePathTrait}; /// A struct for holding an address to initialize a storage path with. The members (not direct -/// members, but accessible using deref) of a contract state are either `StorageBase` or +/// members, but accessible using `deref`) of a contract state are either `StorageBase` or /// `FlattenedStorage` instances, with the generic type representing the type of the stored member. pub struct StorageBase { pub __base_address__: felt252, @@ -24,7 +33,6 @@ impl StorageBaseDeref of core::ops::Deref> { } } - /// A type that represents a flattened storage, i.e. a storage object which does not have any effect /// on the path taken into consideration when computing the address of the storage object. pub struct FlattenedStorage {} @@ -53,24 +61,24 @@ impl MutableFlattenedStorageDeref< } } -/// A trait for creating the struct containing the StorageBase or FlattenedStorage of all the +/// A trait for creating the struct containing the `StorageBase` or `FlattenedStorage` of all the /// members of a contract state. pub trait StorageTrait { - /// The type of the struct containing the StorageBase or FlattenedStorage of all the members of - /// a the type `T`. + /// The type of the struct containing the `StorageBase` or `FlattenedStorage` of all the members + /// of the type `T`. type BaseType; - /// Creates a struct containing the StorageBase or FlattenedStorage of all the members of a + /// Creates a struct containing the `StorageBase` or `FlattenedStorage` of all the members of a /// contract state. Should be called from the `deref` method of the contract state. fn storage(self: FlattenedStorage) -> Self::BaseType; } -/// A trait for creating the struct containing the mutable StorageBase or FlattenedStorage of all -/// the members of a contract state. +/// A trait for creating the struct containing the mutable `StorageBase` or `FlattenedStorage` of +/// all the members of a contract state. pub trait StorageTraitMut { - /// The type of the struct containing the mutable StorageBase or FlattenedStorage of all the - /// members of a the type `T`. + /// The type of the struct containing the mutable `StorageBase` or `FlattenedStorage` of all the + /// members of the type `T`. type BaseType; - /// Creates a struct containing a mutable version of the StorageBase or FlattenedStorage of + /// Creates a struct containing a mutable version of the `StorageBase` or `FlattenedStorage` of /// all the members of a contract state. Should be called from the `deref` method of the /// contract state. fn storage_mut(self: FlattenedStorage>) -> Self::BaseType;