From c216934c880bb22b1f74d07cbbd0fbf69705f3e7 Mon Sep 17 00:00:00 2001 From: julio4 <30329843+julio4@users.noreply.github.com> Date: Thu, 9 Jan 2025 13:20:08 +0100 Subject: [PATCH] move IntoIterRange to starknet::storage --- corelib/src/starknet/storage.cairo | 18 +++++++++++++++--- corelib/src/starknet/storage/vec.cairo | 22 ++++++---------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/corelib/src/starknet/storage.cairo b/corelib/src/starknet/storage.cairo index 1ac3c94d42a..fa16630cb08 100644 --- a/corelib/src/starknet/storage.cairo +++ b/corelib/src/starknet/storage.cairo @@ -68,7 +68,6 @@ //! The generic type of the storage object can also be wrapped with a `Mutable` type, which //! indicates that the storage object is mutable, i.e., it was created from a `ref` contract state, //! and thus the object can be written to. - use core::hash::HashStateTrait; #[allow(unused_imports)] use core::pedersen::HashState; @@ -78,8 +77,11 @@ use starknet::SyscallResult; use starknet::storage_access::{StorageBaseAddress, storage_base_address_from_felt252}; mod vec; -pub use vec::{IntoIterRange, MutableVecTrait, Vec, VecTrait}; -use vec::{MutableVecIndexView, VecIndexView}; +use vec::{ + MutableVecIndexView, MutableVecIntoIterRange, PathableMutableVecIntoIterRange, + PathableVecIntoIterRange, VecIndexView, VecIntoIterRange, +}; +pub use vec::{MutableVecTrait, Vec, VecTrait}; mod storage_node; pub use storage_node::{StorageNode, StorageNodeMut}; @@ -438,3 +440,13 @@ trait MutableTrait { impl MutableImpl of MutableTrait> { type InnerType = T; } + +/// Trait for turning collection of values into an iterator over a specific range. +pub trait IntoIterRange { + type IntoIter; + impl Iterator: Iterator; + /// Creates an iterator over a range from a collection. + fn into_iter_range(self: T, range: core::ops::Range) -> Self::IntoIter; + /// Creates an iterator over the full range of a collection. + fn into_iter_full_range(self: T) -> Self::IntoIter; +} diff --git a/corelib/src/starknet/storage/vec.cairo b/corelib/src/starknet/storage/vec.cairo index 47dcb7a7b8d..18f3fdd3405 100644 --- a/corelib/src/starknet/storage/vec.cairo +++ b/corelib/src/starknet/storage/vec.cairo @@ -77,11 +77,11 @@ //! arr //! } //! ``` -use core::iter::{IntoIterator, Iterator}; use core::ops::Range; use super::{ - Mutable, StorageAsPath, StorageAsPointer, StoragePath, StoragePathTrait, StoragePathUpdateTrait, - StoragePointer0Offset, StoragePointerReadAccess, StoragePointerWriteAccess, + IntoIterRange, Mutable, StorageAsPath, StorageAsPointer, StoragePath, StoragePathTrait, + StoragePathUpdateTrait, StoragePointer0Offset, StoragePointerReadAccess, + StoragePointerWriteAccess, }; /// Represents a dynamic array in contract storage. @@ -397,16 +397,6 @@ pub impl MutableVecIndexView< } } -/// Turn a collection of values into an iterator over a specific range. -pub trait IntoIterRange { - type IntoIter; - impl Iterator: Iterator; - /// Creates an iterator over a range from a collection. - fn into_iter_range(self: T, range: Range) -> Self::IntoIter; - /// Creates an iterator over the full range of a collection. - fn into_iter_full_range(self: T) -> Self::IntoIter; -} - /// An iterator struct over a `Vec` in storage. #[derive(Drop)] pub struct VecIter> { @@ -422,7 +412,7 @@ impl VecIterator, +Drop, +Copy> of Itera } // Implement `IntoIterRange` for `StoragePath>` -impl VecIntoIterRange< +pub impl VecIntoIterRange< T, impl VecTraitImpl: VecTrait>>, > of IntoIterRange>> { type IntoIter = VecIter>, VecTraitImpl>; @@ -473,7 +463,7 @@ impl MutableVecIterator< } // Implement `IntoIterRange` for `StoragePath>>` -impl MutableVecIntoIterRange< +pub impl MutableVecIntoIterRange< T, impl MutVecTraitImpl: MutableVecTrait>>>, > of IntoIterRange>>> { type IntoIter = MutableVecIter>>, MutVecTraitImpl>; @@ -489,7 +479,7 @@ impl MutableVecIntoIterRange< /// Implement `IntoIterRange` for any type that implements StorageAsPath into a storage path /// that implements MutableVecTrait. -impl PathableMutableVecIntoIterRange< +pub impl PathableMutableVecIntoIterRange< T, +Destruct, impl PathImpl: StorageAsPath,