Combination
what it is
combination is a lib to do math jobs like permutate and combinate data from vec.
example
extern crate combination;
use *;
API
combine
Get combination data from a vec
- for example
use *;
let val = from_vec;
for item in val
- and will get:
[10, 20]
[10, 30]
[10, 40]
[20, 30]
[20, 40]
[30, 40]
permutate
Get permutation data from a vec
- for example
extern crate combination;
use *;
let val = from_vec;
for item in val
- and will get:
[30, 10, 40, 20]
[30, 10, 20, 40]
[40, 10, 30, 20]
[10, 40, 30, 20]
[10, 30, 40, 20]
[10, 30, 20, 40]
[40, 10, 20, 30]
[10, 40, 20, 30]
[10, 20, 40, 30]
[10, 20, 30, 40]
[40, 30, 20, 10]
[30, 40, 20, 10]
[30, 20, 40, 10]
[30, 20, 10, 40]
[40, 20, 30, 10]
[20, 40, 30, 10]
[20, 30, 40, 10]
[20, 30, 10, 40]
[40, 20, 10, 30]
[20, 40, 10, 30]
[20, 10, 40, 30]
[20, 10, 30, 40]
Recommend v2 module
In 2022, this package is using edition 2021
now and do more work.
In v2, no longer needs Clone
trait.
And Permutate now allow two params.
What is more, it use Optional value and any input won’t occur error.
Anyway, old api has not changed, don't worry.
Any you are going to use v2 module, just add v2
in the feature, and it is used by default.
Example
use \*;
let str_list = ;
let combine = new;
let res = str_list.try_select.unwrap;
for v in res
As long as use two traits Select and Selector it will work.
V2 module provides two structs which implement Selector
trait, they are Combine
and Permutate
By using them with trait Select
, type as &[T], Vec<T>, [T]
will be able to be selected.
Selector
By implementing this trait, then make any type as a selector.
Then using this for the list, it can select value from the list as custom mode.
Example
;
it will be