Trait AsFlatRawIter

Source
pub trait AsFlatRawIter {
    // Required method
    unsafe fn iter(&self) -> FlatRawIter ;

    // Provided methods
    unsafe fn par_iter(&self) -> ParFlatRawIter { ... }
    unsafe fn iter_of<T>(&self) -> FlatIter<'_, T>  { ... }
    unsafe fn iter_mut_of<T>(&mut self) -> FlatIterMut<'_, T>  { ... }
    unsafe fn par_iter_of<T>(&self) -> ParFlatIter<'_, T> { ... }
    unsafe fn par_iter_mut_of<T>(&mut self) -> ParFlatIterMut<'_, T> { ... }
}
Expand description

A trait to create type-erased flatten iterators from nested types such as Vec<Vec<T>>.

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

Required Methods§

Source

unsafe fn iter(&self) -> FlatRawIter

Returns a new FlatRawIter.

§Safety
  • The created iterator’s lifetime must rely on the &self.
§Examples
use my_ecs::{tinfo, ds::{ChunkAnyVec, AsFlatRawIter}};

// `ChunkAnyVec` implements `AsFlatRawIter`.
let chunk_cap = 2;
let v = ChunkAnyVec::new(tinfo!(i32), chunk_cap);
let iter = unsafe { v.iter() };

Provided Methods§

Source

unsafe fn par_iter(&self) -> ParFlatRawIter

Returns a new ParFlatRawIter.

§Safety
  • The created iterator’s lifetime must rely on the &self.
§Examples
use my_ecs::{tinfo, ds::{ChunkAnyVec, AsFlatRawIter}};

// `ChunkAnyVec` implements `AsFlatRawIter`.
let chunk_cap = 2;
let v = ChunkAnyVec::new(tinfo!(i32), chunk_cap);
let iter = unsafe { v.par_iter() };
Source

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

Returns a new iterator.

§Safety

The given type T must be proper type.

§Examples
use my_ecs::{tinfo, ds::{ChunkAnyVec, AsFlatRawIter}};

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

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

Returns a new mutable iterator.

§Safety

The given type T must be proper type.

§Examples
use my_ecs::{tinfo, ds::{ChunkAnyVec, AsFlatRawIter}};

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

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

Returns a new parallel iterator.

§Safety

The given type T must be proper type.

§Examples
use my_ecs::{tinfo, ds::{ChunkAnyVec, AsFlatRawIter}};

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

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

Returns a new parallel mutable iterator.

§Safety

The given type T must be proper type.

§Examples
use my_ecs::{tinfo, ds::{ChunkAnyVec, AsFlatRawIter}};

// `ChunkAnyVec` implements `AsFlatRawIter`.
let chunk_cap = 2;
let mut v = ChunkAnyVec::new(tinfo!(i32), chunk_cap);
unsafe {
    v.push(0_i32);
    v.push(1_i32);
}
for v in unsafe { AsFlatRawIter::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.

Implementors§