Trait std::slice::CloneSliceAllocPreludeExperimental
[-]
[+]
[src]
pub trait CloneSliceAllocPrelude<T> {
fn to_vec(&self) -> Vec<T>;
fn partitioned(&self, f: |&T| -> bool) -> (Vec<T>, Vec<T>);
fn permutations(&self) -> Permutations<T>;
}Allocating extension methods for slices containing Clone elements.
Required Methods
fn to_vec(&self) -> Vec<T>
Copies self into a new Vec.
fn partitioned(&self, f: |&T| -> bool) -> (Vec<T>, Vec<T>)
Partitions the vector into two vectors (a, b), where all
elements of a satisfy f and all elements of b do not.
fn permutations(&self) -> Permutations<T>
Creates an iterator that yields every possible permutation of the vector in succession.
Example
fn main() { let v = [1i, 2, 3]; let mut perms = v.permutations(); for p in perms { println!("{}", p); } }let v = [1i, 2, 3]; let mut perms = v.permutations(); for p in perms { println!("{}", p); }
Example 2: iterating through permutations one by one.
fn main() { let v = [1i, 2, 3]; let mut perms = v.permutations(); assert_eq!(Some(vec![1i, 2, 3]), perms.next()); assert_eq!(Some(vec![1i, 3, 2]), perms.next()); assert_eq!(Some(vec![3i, 1, 2]), perms.next()); }let v = [1i, 2, 3]; let mut perms = v.permutations(); assert_eq!(Some(vec![1i, 2, 3]), perms.next()); assert_eq!(Some(vec![1i, 3, 2]), perms.next()); assert_eq!(Some(vec![3i, 1, 2]), perms.next());
Implementors
impl<T: Clone> CloneSliceAllocPrelude<T> for [T]