pub unsafe fn unsafe_large_combination<'a, T: 'a>(
    domain: &'a [T],
    r: usize,
    result: *mut [&'a T],
    cb: impl FnMut()
)
Expand description

Generate a r-combination from given domain and call callback function on each combination. The result will be return into ref mut pointer.

Parameter

  1. domain : &[T] - A slice contain a domain to generate r-combination
  2. r : usize - A size of combination
  3. result : *mut [&T] - A mutable pointer to store result
  4. cb : FnMut() - A callback that notify caller on each combination

Panic

  • It panic when r > domain.len() or r > result.len()

Rationale

This function took *mut [&T] to store result. It allow caller to easily share result outside callback function without copying/cloning each result. It sacrifice safety for performance.

Safety

  • It doesn’t check whether the pointer is valid or not.
  • It doesn’t free memory occupied by result.
  • It may cause data race
  • Mutating result may cause undesired behavior.
  • Storing result will get overwritten when new combination is return.
  • All other unsafe Rust condition may applied.