Trait AsRawIter

Source
pub trait AsRawIter {
    // Required method
    fn iter(&self) -> RawIter ;

    // Provided methods
    fn par_iter(&self) -> ParRawIter { ... }
    unsafe fn iter_of<T>(&self) -> Iter<'_, T>  { ... }
    unsafe fn iter_mut_of<T>(&mut self) -> IterMut<'_, T>  { ... }
    unsafe fn par_iter_of<T>(&self) -> ParIter<'_, T> { ... }
    unsafe fn par_iter_mut_of<T>(&mut self) -> ParIterMut<'_, T> { ... }
}
Expand description

A trait to create type-erased iterators.

Type-erased iterator RawIter is commonly used in type-erased data containers. Also, the iterators can become parallel iterators that can be split over multiple CPU cores for parallel comuputing.

Required Methods§

Source

fn iter(&self) -> RawIter

Returns a new RawIter.

Give par_iter a try if you need CPU parallel computing.

§Examples
use my_ecs::{tinfo, ds::{AnyVec, AsRawIter}};

// `AnyVec` implements `AsRawIter`.
let v = AnyVec::new(tinfo!(i32));
let iter = v.iter();

Provided Methods§

Source

fn par_iter(&self) -> ParRawIter

Returns a new ParRawIter.

Unlike RawIter, this iterator can be split over multiple CPU cores then consumed at the same time for performance. But note that this is not a silver bullet. It could be worse than sequential iterator RawIter for a short iteration.

§Examples
use my_ecs::{tinfo, ds::{AnyVec, AsRawIter}};

// `AnyVec` implements `AsRawIter`.
let v = AnyVec::new(tinfo!(i32));
let iter = v.par_iter();
Source

unsafe fn iter_of<T>(&self) -> Iter<'_, T>

Returns a new iterator.

§Safety

The given type T must be proper type.

§Examples
use my_ecs::{tinfo, ds::{AnyVec, AsRawIter}};

// `AnyVec` implements `AsRawIter`.
let mut v = AnyVec::new(tinfo!(i32));
unsafe {
    v.push(0_i32);
    v.push(1_i32);
}
for v in unsafe { AsRawIter::iter_of::<i32>(&v) } {
    println!("{v}");
}
Source

unsafe fn iter_mut_of<T>(&mut self) -> IterMut<'_, T>

Returns a new mutable iterator.

§Safety

The given type T must be proper type.

§Examples
use my_ecs::{tinfo, ds::{AnyVec, AsRawIter}};

// `AnyVec` implements `AsRawIter`.
let mut v = AnyVec::new(tinfo!(i32));
unsafe {
    v.push(0_i32);
    v.push(1_i32);
}
for v in unsafe { AsRawIter::iter_mut_of::<i32>(&mut v) } {
    *v += 1;
    println!("{v}");
}
Source

unsafe fn par_iter_of<T>(&self) -> ParIter<'_, T>

Returns a new parallel iterator.

§Safety

The given type T must be proper type.

§Examples
use my_ecs::{tinfo, ds::{AnyVec, AsRawIter}};

// `AnyVec` implements `AsRawIter`.
let mut v = AnyVec::new(tinfo!(i32));
unsafe {
    v.push(0_i32);
    v.push(1_i32);
}
for v in unsafe { AsRawIter::par_iter_of::<i32>(&v) } {
    println!("{v}");
}
Source

unsafe fn par_iter_mut_of<T>(&mut self) -> ParIterMut<'_, T>

Returns a new parallel mutable iterator.

§Safety

The given type T must be proper type.

§Examples
use my_ecs::{tinfo, ds::{AnyVec, AsRawIter}};

// `AnyVec` implements `AsRawIter`.
let mut v = AnyVec::new(tinfo!(i32));
unsafe {
    v.push(0_i32);
    v.push(1_i32);
}
for v in unsafe { AsRawIter::par_iter_mut_of::<i32>(&mut v) } {
    *v += 1;
    println!("{v}");
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> AsRawIter for [T]

Source§

fn iter(&self) -> RawIter

Implementors§