Trait TrustedChunkSizedCollection

Source
pub unsafe trait TrustedChunkSizedCollection: TrustedSizedCollection {
    // Required method
    fn chunk_size(&self) -> usize;

    // Provided methods
    fn num_elements(&self) -> usize { ... }
    fn num_chunks(&self) -> usize { ... }
}
Expand description

A sized collection that can be used in chunks of equal size.

This trait can be trusted by unsafe code thanks to the invariants below.

§Safety

Implementors of this trait must guarantee the following invariants:

  • Each chunk must have the same size equal to chunk_size.
  • The collection holds a number of chunks equal to num_chunks.
  • The len method must be an alias to num_chunks (it must hold collection.len() == collection.num_chunks()).
  • The collection must hold a number of elements equal to num_elements.
  • The number of elements in the collection is equal to the number of chunks in the collection times the chunk size (in other words: num_elements = num_chunks * chunk_size).

Required Methods§

Source

fn chunk_size(&self) -> usize

Returns the number of elements in each chunk.

§Examples
let collection = vec![0; 20].into_par_chunk_index(5);
assert_eq!(collection.chunk_size(), 5);

Provided Methods§

Source

fn num_elements(&self) -> usize

Returns the number of elements in the collection.

§Examples
let collection = vec![0; 20].into_par_chunk_index(5);
assert_eq!(collection.num_elements(), 20);
Source

fn num_chunks(&self) -> usize

Returns the number of chunks in the collection.

This is equivalent to len.

§Examples
let collection = vec![0; 20].into_par_chunk_index(5);
assert_eq!(collection.num_chunks(), 4);
assert_eq!(collection.len(), 4);

Implementations on Foreign Types§

Source§

impl<T, const N: usize> TrustedChunkSizedCollection for [[T; N]]

Source§

impl<T, const N: usize, const M: usize> TrustedChunkSizedCollection for [[T; N]; M]

Implementors§