Skip to content

Commit

Permalink
Core Lib Documentation:storage_base module (#7039)
Browse files Browse the repository at this point in the history
Co-authored-by: enitrat <[email protected]>
  • Loading branch information
TAdev0 and enitrat authored Jan 10, 2025
1 parent e95ad43 commit ec7c129
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions corelib/src/starknet/storage/storage_base.cairo
Original file line number Diff line number Diff line change
@@ -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<T> {
pub __base_address__: felt252,
Expand All @@ -24,7 +33,6 @@ impl StorageBaseDeref<T> of core::ops::Deref<StorageBase<T>> {
}
}


/// 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<T> {}
Expand Down Expand Up @@ -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<T> {
/// 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<T>) -> 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<T> {
/// 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<Mutable<T>>) -> Self::BaseType;
Expand Down

0 comments on commit ec7c129

Please sign in to comment.