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
lenmethod must be an alias tonum_chunks(it must holdcollection.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§
Sourcefn chunk_size(&self) -> usize
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§
Sourcefn num_elements(&self) -> usize
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);