cairo-native 0.9.0-rc.3

A compiler to convert Cairo's IR Sierra code to MLIR and execute it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
//! Vector-like storage collection for persisting data in contract storage.
//!
//! This module provides a vector-like collection that stores elements in contract storage.
//! Unlike memory arrays, storage vectors persist data onchain, meaning that values can be retrieved
//! even after the end of the current context.
//!
//! # Storage Layout
//!
//! A storage vector consists of two parts:
//! - The vector length stored at the base storage address (`sn_keccak(variable_name)`)
//! - The elements stored at addresses computed as `h(base_address, index)` where:
//!   - `h` is the Pedersen hash function
//!   - `index` is the element's position in the vector
//!
//! # Interacting with [`Vec`]
//!
//! Storage vectors can be accessed through two sets of traits:
//!
//! 1. Read-only access using `VecTrait`:
//!    ```
//!    // Get length
//!    let len = self.my_vec.len();
//!
//!    // Read element (panics if out of bounds)
//!    let value = self.my_vec.at(0).read();
//!
//!    // Read element (returns Option)
//!    let maybe_value: Option<u256> = self.my_vec.get(0).map(|ptr| ptr.read());
//!    ```
//!
//! 2. Mutable access using `MutableVecTrait`:
//!    ```
//!    // Append new element using push
//!    self.my_vec.push(value);
//!
//!    // Allocate space for a new element (useful for nested vectors)
//!    let new_slot = self.my_vec.allocate();
//!
//!    // Modify existing element
//!    self.my_vec.at(0).write(new_value);
//!    ```
//!
//! # Examples
//!
//! Basic usage:
//!
//! ```
//! use starknet::storage::{Vec, VecTrait, MutableVecTrait, StoragePointerReadAccess,
//! StoragePointerWriteAccess};
//!
//! #[storage]
//! struct Storage {
//!     numbers: Vec<u256>,
//! }
//!
//! fn store_number(ref self: ContractState, number: u256) {
//!     // Append new number
//!     self.numbers.push(number);
//!
//!     // Read first number
//!     let first = self.numbers[0].read();
//!
//!     // Get current length
//!     let size = self.numbers.len();
//! }
//! ```
//!
//! Loading the numbers into a memory array:
//!
//! ```
//! use starknet::storage::{Vec, VecTrait, StoragePointerReadAccess};
//!
//! fn to_array(self: @ContractState) -> Array<u256> {
//!     let mut arr = array![];
//!
//!     let len = self.numbers.len();
//!     for i in 0..len {
//!         arr.append(self.numbers[i].read());
//!     }
//!     arr
//! }
//! ```
use core::ops::Range;
use super::{
    IntoIterRange, Mutable, StorageAsPath, StorageAsPointer, StoragePath,
    StoragePathMutableConversion, StoragePathTrait, StoragePathUpdateTrait, StoragePointer0Offset,
    StoragePointerReadAccess, StoragePointerWriteAccess,
};

/// Represents a dynamic array in contract storage.
///
/// This type is zero-sized and cannot be instantiated.
/// Vectors can only be used in storage contexts and manipulated using the associated `VecTrait`
/// and `MutableVecTrait` traits.
#[phantom]
pub struct Vec<T> {}

impl VecDrop<T> of Drop<Vec<T>> {}
impl VecCopy<T> of Copy<Vec<T>> {}

/// Implement `as_ptr` for `Vec`.
impl VecAsPointer<T> of StorageAsPointer<StoragePath<Vec<T>>> {
    type Value = u64;
    fn as_ptr(self: @StoragePath<Vec<T>>) -> StoragePointer0Offset<u64> {
        StoragePointer0Offset { __storage_pointer_address__: (*self).finalize() }
    }
}

/// Implement `as_ptr` for `Mutable<Vec>`.
impl MutableVecAsPointer<T> of StorageAsPointer<StoragePath<Mutable<Vec<T>>>> {
    type Value = Mutable<u64>;
    fn as_ptr(self: @StoragePath<Mutable<Vec<T>>>) -> StoragePointer0Offset<Mutable<u64>> {
        StoragePointer0Offset { __storage_pointer_address__: (*self).finalize() }
    }
}

/// Provides read-only access to elements in a storage [`Vec`].
///
/// This trait enables retrieving elements and checking the vector's length without
/// modifying the underlying storage.
pub trait VecTrait<T> {
    type ElementType;

    /// Returns a storage path to the element at the specified index, or `None` if out of bounds.
    ///
    /// # Examples
    ///
    /// ```
    /// use starknet::storage::{Vec, VecTrait, StoragePointerReadAccess};
    ///
    /// #[storage]
    /// struct Storage {
    ///     numbers: Vec<u256>,
    /// }
    ///
    /// fn maybe_number(self: @ContractState, index: u64) -> Option<u256> {
    ///     self.numbers.get(index).map(|ptr| ptr.read())
    /// }
    /// ```
    fn get(self: T, index: u64) -> Option<StoragePath<Self::ElementType>>;

    /// Returns a storage path to access the element at the specified index.
    ///
    /// # Panics
    ///
    /// Panics if the index is out of bounds.
    ///
    /// # Examples
    ///
    /// ```
    /// use starknet::storage::{Vec, VecTrait, StoragePointerReadAccess};
    ///
    /// #[storage]
    /// struct Storage {
    ///     numbers: Vec<u256>,
    /// }
    ///
    /// fn get_number(self: @ContractState, index: u64) -> u256 {
    ///     self.numbers.at(index).read()
    /// }
    /// ```
    fn at(self: T, index: u64) -> StoragePath<Self::ElementType>;

    /// Returns the number of elements in the vector.
    ///
    /// The length is stored at the vector's base storage address and is automatically
    /// updated when elements are appended.
    ///
    /// # Examples
    ///
    /// ```
    /// use starknet::storage::{Vec, VecTrait};
    ///
    /// #[storage]
    /// struct Storage {
    ///     numbers: Vec<u256>,
    /// }
    ///
    /// fn is_empty(self: @ContractState) -> bool {
    ///     self.numbers.len() == 0
    /// }
    /// ```
    fn len(self: T) -> u64;
}

/// Implement `VecTrait` for `StoragePath<Vec<T>>`.
impl VecImpl<T> of VecTrait<StoragePath<Vec<T>>> {
    type ElementType = T;

    fn get(self: StoragePath<Vec<T>>, index: u64) -> Option<StoragePath<T>> {
        let vec_len = self.len();
        if index < vec_len {
            Some(self.update(index))
        } else {
            None
        }
    }

    fn at(self: StoragePath<Vec<T>>, index: u64) -> StoragePath<T> {
        assert!(index < self.len(), "Index out of bounds");
        self.update(index)
    }

    fn len(self: StoragePath<Vec<T>>) -> u64 {
        self.as_ptr().read()
    }
}

/// Implement `VecTrait` for any type that implements `StorageAsPath` into a storage path
/// that implements `VecTrait`.
impl PathableVecImpl<
    T,
    +Drop<T>,
    impl PathImpl: StorageAsPath<T>,
    impl VecTraitImpl: VecTrait<StoragePath<PathImpl::Value>>,
> of VecTrait<T> {
    type ElementType = VecTraitImpl::ElementType;

    fn get(self: T, index: u64) -> Option<StoragePath<VecTraitImpl::ElementType>> {
        self.as_path().get(index)
    }

    fn at(self: T, index: u64) -> StoragePath<VecTraitImpl::ElementType> {
        self.as_path().at(index)
    }

    fn len(self: T) -> u64 {
        self.as_path().len()
    }
}

/// Provides mutable access to elements in a storage [`Vec`].
///
/// This trait extends the read functionality with methods to append new elements
/// and modify existing ones.
pub trait MutableVecTrait<T> {
    type ElementType;

    /// Returns a mutable storage path to the element at the specified index, or `None` if out of
    /// bounds.
    ///
    /// # Examples
    ///
    /// ```
    /// use starknet::storage::{Vec, MutableVecTrait, StoragePointerWriteAccess};
    ///
    /// #[storage]
    /// struct Storage {
    ///     numbers: Vec<u256>,
    /// }
    ///
    /// fn set_number(ref self: ContractState, index: u64, number: u256) -> bool {
    ///     if let Some(ptr) = self.numbers.get(index) {
    ///         ptr.write(number);
    ///         true
    ///     } else {
    ///         false
    ///     }
    /// }
    /// ```
    fn get(self: T, index: u64) -> Option<StoragePath<Mutable<Self::ElementType>>>;

    /// Returns a mutable storage path to the element at the specified index.
    ///
    /// # Panics
    ///
    /// Panics if the index is out of bounds.
    ///
    /// # Examples
    ///
    /// ```
    /// use starknet::storage::{Vec, MutableVecTrait, StoragePointerWriteAccess};
    ///
    /// #[storage]
    /// struct Storage {
    ///     numbers: Vec<u256>,
    /// }
    ///
    /// fn set_number(ref self: ContractState, index: u64, number: u256) {
    ///     self.numbers.at(index).write(number);
    /// }
    /// ```
    fn at(self: T, index: u64) -> StoragePath<Mutable<Self::ElementType>>;

    /// Returns the number of elements in the vector.
    ///
    /// The length is stored at the vector's base storage address and is automatically
    /// updated when elements are appended.
    ///
    /// # Examples
    ///
    /// ```
    /// use starknet::storage::{Vec, MutableVecTrait};
    ///
    /// #[storage]
    /// struct Storage {
    ///     numbers: Vec<u256>,
    /// }
    ///
    /// fn is_empty(self: @ContractState) -> bool {
    ///     self.numbers.len() == 0
    /// }
    /// ```
    fn len(self: T) -> u64;

    /// Returns a mutable storage path to write a new element at the end of the vector.
    ///
    /// This operation:
    /// 1. Increments the vector's length
    /// 2. Returns a storage path to write the new element
    ///
    /// # Examples
    ///
    /// ```
    /// use starknet::storage::{Vec, MutableVecTrait, StoragePointerWriteAccess};
    ///
    /// #[storage]
    /// struct Storage {
    ///     numbers: Vec<u256>,
    /// }
    ///
    /// fn push_number(ref self: ContractState, number: u256) {
    ///     self.numbers.append().write(number);
    /// }
    /// ```
    #[deprecated(
        feature: "starknet-storage-deprecation",
        note: "Use `starknet::storage::MutableVecTrait::push` or `starknet::storage::MutableVecTrait::allocate` instead.",
    )]
    fn append(self: T) -> StoragePath<Mutable<Self::ElementType>> {
        Self::allocate(self)
    }

    /// Allocates space for a new element at the end of the vector, returning a mutable storage path
    /// to write the element.
    ///
    /// This function is a replacement for the deprecated `append` function, which allowed
    /// appending new elements to a vector.
    /// Unlike `push`, which gets an object to write to the vector, `allocate` is specifically
    /// useful when you need to prepare space for elements of unknown or dynamic size (e.g.,
    /// appending another vector).
    ///
    /// # Use Case
    ///
    /// `allocate` is essential when pushing a vector into another vector, as the size of the
    /// nested vector is unknown at compile time. It allows the caller to allocate the required
    /// space first, then write the nested vector into the allocated space using `.write()`.
    ///
    /// This is necessary because pushing directly (e.g., `vec.push(nested_vec)`) is not supported
    /// due to `Vec` being only a storage abstraction.
    ///
    /// # Deprecation Note
    ///
    /// The `append` function is now deprecated. Use `allocate` to achieve the same functionality
    /// with improved clarity and flexibility.
    ///
    /// # Examples
    ///
    /// ```
    /// use starknet::storage::{Vec, MutableVecTrait, StoragePointerWriteAccess};
    ///
    /// #[storage]
    /// struct Storage {
    ///     numbers: Vec<Vec<u256>>,
    /// }
    ///
    /// fn append_nested_vector(ref self: ContractState, elements: Array<u256>) {
    ///     // Allocate space for the nested vector in the outer vector.
    ///     let new_vec_storage_path = self.numbers.allocate();
    ///     for element in elements {
    ///         new_vec_storage_path.push(element)
    ///     }
    /// }
    /// ```
    fn allocate(self: T) -> StoragePath<Mutable<Self::ElementType>>;

    /// Pushes a new value onto the vector.
    ///
    /// This operation:
    /// 1. Increments the vector's length.
    /// 2. Writes the provided value to the new storage location at the end of the vector.
    ///
    /// # Note
    ///
    /// If you need to allocate storage without writing a value (e.g., when appending another
    /// vector), consider using [`allocate`] instead.
    ///
    /// # Examples
    ///
    /// ```
    /// use starknet::storage::{Vec, MutableVecTrait};
    ///
    /// #[storage]
    /// struct Storage {
    ///     numbers: Vec<u256>,
    /// }
    ///
    /// fn push_number(ref self: ContractState, number: u256) {
    ///     self.numbers.push(number);
    /// }
    /// ```
    fn push<+Drop<Self::ElementType>, +starknet::Store<Self::ElementType>>(
        self: T, value: Self::ElementType,
    );

    /// Pops the last value off the vector.
    ///
    /// This operation:
    /// 1. Retrieves the value stored at the last position in the vector.
    /// 2. Decrements the vector's length.
    /// 3. Returns the retrieved value or `None` if the vector is empty.
    ///
    /// # Examples
    ///
    /// ```
    /// use starknet::storage::{Vec, MutableVecTrait};
    ///
    /// #[storage]
    /// struct Storage {
    ///     numbers: Vec<u256>,
    /// }
    ///
    /// fn pop_number(ref self: ContractState) -> Option<u256> {
    ///     self.numbers.pop()
    /// }
    /// ```
    fn pop<+Drop<Self::ElementType>, +starknet::Store<Self::ElementType>>(
        self: T,
    ) -> Option<Self::ElementType>;
}

/// Implement `MutableVecTrait` for `StoragePath<Mutable<Vec<T>>>`.
impl MutableVecImpl<T> of MutableVecTrait<StoragePath<Mutable<Vec<T>>>> {
    type ElementType = T;

    fn get(self: StoragePath<Mutable<Vec<T>>>, index: u64) -> Option<StoragePath<Mutable<T>>> {
        let vec_len = self.len();
        if index < vec_len {
            Some(self.update(index))
        } else {
            None
        }
    }

    fn at(self: StoragePath<Mutable<Vec<T>>>, index: u64) -> StoragePath<Mutable<T>> {
        assert!(index < self.len(), "Index out of bounds");
        self.update(index)
    }

    fn len(self: StoragePath<Mutable<Vec<T>>>) -> u64 {
        self.as_non_mut().len()
    }

    fn allocate(self: StoragePath<Mutable<Vec<T>>>) -> StoragePath<Mutable<T>> {
        let vec_len = self.len();
        self.as_ptr().write(vec_len + 1);
        self.update(vec_len)
    }

    fn push<+Drop<Self::ElementType>, +starknet::Store<Self::ElementType>>(
        self: StoragePath<Mutable<Vec<T>>>, value: Self::ElementType,
    ) {
        self.allocate().write(value);
    }

    fn pop<+Drop<Self::ElementType>, +starknet::Store<Self::ElementType>>(
        self: StoragePath<Mutable<Vec<T>>>,
    ) -> Option<Self::ElementType> {
        let len_ptr = self.as_ptr();
        let vec_len: u64 = len_ptr.read();
        if vec_len == 0 {
            return None;
        }
        let entry: StoragePath<Mutable<T>> = self.update(vec_len - 1);
        let last_element = entry.read();
        // Remove the element's data from the storage.
        let entry_ptr = entry.as_ptr();
        starknet::SyscallResultTrait::unwrap_syscall(
            starknet::Store::<
                Self::ElementType,
            >::scrub(0, entry_ptr.__storage_pointer_address__, 0),
        );
        len_ptr.write(vec_len - 1);
        Some(last_element)
    }
}

/// Implement `MutableVecTrait` for any type that implements StorageAsPath into a storage
/// path that implements MutableVecTrait.
impl PathableMutableVecImpl<
    T,
    +Drop<T>,
    impl PathImpl: StorageAsPath<T>,
    impl VecTraitImpl: MutableVecTrait<StoragePath<PathImpl::Value>>,
> of MutableVecTrait<T> {
    type ElementType = VecTraitImpl::ElementType;

    fn get(self: T, index: u64) -> Option<StoragePath<Mutable<VecTraitImpl::ElementType>>> {
        self.as_path().get(index)
    }

    fn at(self: T, index: u64) -> StoragePath<Mutable<VecTraitImpl::ElementType>> {
        self.as_path().at(index)
    }

    fn len(self: T) -> u64 {
        self.as_path().len()
    }

    fn allocate(self: T) -> StoragePath<Mutable<VecTraitImpl::ElementType>> {
        self.as_path().allocate()
    }

    fn push<+Drop<Self::ElementType>, +starknet::Store<Self::ElementType>>(
        self: T, value: Self::ElementType,
    ) {
        self.as_path().push(value)
    }

    fn pop<+Drop<Self::ElementType>, +starknet::Store<Self::ElementType>>(
        self: T,
    ) -> Option<Self::ElementType> {
        self.as_path().pop()
    }
}

pub impl VecIndexView<
    VecT, impl VecImpl: VecTrait<VecT>, +Copy<VecT>,
> of core::ops::IndexView<VecT, u64> {
    type Target = StoragePath<VecImpl::ElementType>;
    fn index(self: @VecT, index: u64) -> Self::Target {
        (*self).at(index)
    }
}

pub impl MutableVecIndexView<
    VecT, impl VecImpl: MutableVecTrait<VecT>, +Copy<VecT>,
> of core::ops::IndexView<VecT, u64> {
    type Target = StoragePath<Mutable<VecImpl::ElementType>>;
    fn index(self: @VecT, index: u64) -> Self::Target {
        (*self).at(index)
    }
}

/// An iterator struct over a `Vec` in storage.
#[derive(Drop)]
pub struct VecIter<T, impl VecTraitImpl: VecTrait<T>> {
    vec: T,
    current_index: IntoIterator::<crate::ops::Range<u64>>::IntoIter,
}

impl VecIterator<T, impl VecTraitImpl: VecTrait<T>, +Drop<T>, +Copy<T>> of Iterator<VecIter<T>> {
    type Item = StoragePath<VecTraitImpl::ElementType>;
    fn next(ref self: VecIter<T>) -> Option<Self::Item> {
        self.vec.get(self.current_index.next()?)
    }
}

// Implement `IntoIterRange` for `StoragePath<Vec<T>>`
pub impl VecIntoIterRange<
    T, impl VecTraitImpl: VecTrait<StoragePath<Vec<T>>>,
> of IntoIterRange<StoragePath<Vec<T>>> {
    type IntoIter = VecIter<StoragePath<Vec<T>>, VecTraitImpl>;
    #[inline]
    fn into_iter_range(self: StoragePath<Vec<T>>, range: Range<u64>) -> Self::IntoIter {
        VecIter { current_index: range.into_iter(), vec: self }
    }
    #[inline]
    fn into_iter_full_range(self: StoragePath<Vec<T>>) -> Self::IntoIter {
        VecIter { current_index: (0..core::num::traits::Bounded::MAX).into_iter(), vec: self }
    }
}

/// Implement `IntoIterRange` for any type that implements StorageAsPath into a storage path
/// that implements VecTrait.
pub impl PathableVecIntoIterRange<
    T,
    +Destruct<T>,
    impl PathImpl: StorageAsPath<T>,
    impl VecTraitImpl: VecTrait<StoragePath<PathImpl::Value>>,
> of IntoIterRange<T> {
    type IntoIter = VecIter<StoragePath<PathImpl::Value>, VecTraitImpl>;
    #[inline]
    fn into_iter_range(self: T, range: Range<u64>) -> Self::IntoIter {
        VecIter { current_index: range.into_iter(), vec: self.as_path() }
    }
    #[inline]
    fn into_iter_full_range(self: T) -> Self::IntoIter {
        let vec = self.as_path();
        VecIter { current_index: (0..core::num::traits::Bounded::MAX).into_iter(), vec }
    }
}

/// An iterator struct over a `Mutable<Vec>` in storage.
#[derive(Drop)]
struct MutableVecIter<T, impl MutVecTraitImpl: MutableVecTrait<T>> {
    vec: T,
    current_index: IntoIterator::<crate::ops::Range<u64>>::IntoIter,
}

impl MutableVecIterator<
    T, +Drop<T>, +Copy<T>, impl MutVecTraitImpl: MutableVecTrait<T>,
> of Iterator<MutableVecIter<T>> {
    type Item = StoragePath<Mutable<MutVecTraitImpl::ElementType>>;
    fn next(ref self: MutableVecIter<T>) -> Option<Self::Item> {
        self.vec.get(self.current_index.next()?)
    }
}

// Implement `IntoIterRange` for `StoragePath<Mutable<Vec<T>>>`
pub impl MutableVecIntoIterRange<
    T, impl MutVecTraitImpl: MutableVecTrait<StoragePath<Mutable<Vec<T>>>>,
> of IntoIterRange<StoragePath<Mutable<Vec<T>>>> {
    type IntoIter = MutableVecIter<StoragePath<Mutable<Vec<T>>>, MutVecTraitImpl>;
    #[inline]
    fn into_iter_range(self: StoragePath<Mutable<Vec<T>>>, range: Range<u64>) -> Self::IntoIter {
        MutableVecIter { current_index: range.into_iter(), vec: self }
    }
    #[inline]
    fn into_iter_full_range(self: StoragePath<Mutable<Vec<T>>>) -> Self::IntoIter {
        MutableVecIter {
            current_index: (0..core::num::traits::Bounded::MAX).into_iter(), vec: self,
        }
    }
}

/// Implement `IntoIterRange` for any type that implements StorageAsPath into a storage path
/// that implements MutableVecTrait.
pub impl PathableMutableVecIntoIterRange<
    T,
    +Destruct<T>,
    impl PathImpl: StorageAsPath<T>,
    impl MutVecTraitImpl: MutableVecTrait<StoragePath<PathImpl::Value>>,
> of IntoIterRange<T> {
    type IntoIter = MutableVecIter<StoragePath<PathImpl::Value>, MutVecTraitImpl>;
    #[inline]
    fn into_iter_range(self: T, range: Range<u64>) -> Self::IntoIter {
        MutableVecIter { current_index: range.into_iter(), vec: self.as_path() }
    }
    #[inline]
    fn into_iter_full_range(self: T) -> Self::IntoIter {
        let vec = self.as_path();
        MutableVecIter { current_index: (0..core::num::traits::Bounded::MAX).into_iter(), vec }
    }
}

/// Implementation of `ValidStorageTypeTrait` for `Vec<T>`.
/// This ensures that Starknet storage vectors (`Vec<T>`) are valid storage types,
/// as long as the contained type `T` is itself a valid storage type (`ValidStorageTypeTrait<T>`).
/// This allows vectors to be stored in contract storage, provided that their elements
/// conform to the required storage constraints.
use starknet::storage::ValidStorageTypeTrait;
impl ValidStorageTypeVecTrait<T, +ValidStorageTypeTrait<T>> of ValidStorageTypeTrait<Vec<T>>;