Skip to main content

ForEachRange

Trait ForEachRange 

Source
pub trait ForEachRange {
    // Required method
    fn for_each_rows(
        self,
        builder: impl Fn(i64) -> ViewHandle + 'static,
    ) -> ViewHandle;
}
Expand description

ForEach(0..<count) { index in … }.

SwiftUI calls the closure whenever it rebuilds the body, not just once at construction, so the builder is leaked deliberately — it has to outlive the ForEach value. A range ForEach can run over.

Swift has two: ForEach(0..<n), which is special-cased and identifies rows by position, and ForEach(a...b, id: \.self), which identifies them by value. Rust spells those 0..n and a..=b, and they reach different SwiftUI initialisers and build different types — so which one a caller wrote is worth keeping rather than normalising away.

Required Methods§

Source

fn for_each_rows( self, builder: impl Fn(i64) -> ViewHandle + 'static, ) -> ViewHandle

Run builder over this range.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ForEachRange for Range<i64>

Source§

fn for_each_rows( self, builder: impl Fn(i64) -> ViewHandle + 'static, ) -> ViewHandle

Source§

impl ForEachRange for RangeInclusive<i64>

Source§

fn for_each_rows( self, builder: impl Fn(i64) -> ViewHandle + 'static, ) -> ViewHandle

Implementors§