Trait collections::slice::CloneSliceExtUnstable [-]  [+] [src]

pub trait CloneSliceExt<T>: ?Sized {
    fn to_vec(&self) -> Vec<T>;
    fn partitioned<F>(&self, f: F) -> (Vec<T>, Vec<T>) where F: FnMut(&T) -> bool;
    fn permutations(&self) -> Permutations<T>;
    fn clone_from_slice(&mut self, &[T]) -> uint;
}

Allocating extension methods for slices containing Clone elements.

Required Methods

fn to_vec(&self) -> Vec<T>

Copies self into a new Vec.

fn partitioned<F>(&self, f: F) -> (Vec<T>, Vec<T>) where F: FnMut(&T) -> bool

Deprecated: use iter().cloned().partition(f) instead.

fn permutations(&self) -> Permutations<T>

Creates an iterator that yields every possible permutation of the vector in succession.

Examples

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);
}

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());

fn clone_from_slice(&mut self, &[T]) -> uint

Copies as many elements from src as it can into self (the shorter of self.len() and src.len()). Returns the number of elements copied.

Example

fn main() { let mut dst = [0i, 0, 0]; let src = [1i, 2]; assert!(dst.clone_from_slice(&src) == 2); assert!(dst == [1, 2, 0]); let src2 = [3i, 4, 5, 6]; assert!(dst.clone_from_slice(&src2) == 3); assert!(dst == [3i, 4, 5]); }
let mut dst = [0i, 0, 0];
let src = [1i, 2];

assert!(dst.clone_from_slice(&src) == 2);
assert!(dst == [1, 2, 0]);

let src2 = [3i, 4, 5, 6];
assert!(dst.clone_from_slice(&src2) == 3);
assert!(dst == [3i, 4, 5]);

Implementors