Trait collections::slice::MutableOrdVector[src]

pub trait MutableOrdVector<T> {
    fn sort(self);
    fn next_permutation(self) -> bool;
    fn prev_permutation(self) -> bool;
}

Methods for mutable vectors with orderable elements, such as in-place sorting.

Required Methods

fn sort(self)

Sort the vector, in place.

This is equivalent to self.sort_by(|a, b| a.cmp(b)).

Example

fn main() { let mut v = [-5i, 4, 1, -3, 2]; v.sort(); assert!(v == [-5i, -3, 1, 2, 4]); }
let mut v = [-5i, 4, 1, -3, 2];

v.sort();
assert!(v == [-5i, -3, 1, 2, 4]);

fn next_permutation(self) -> bool

Mutates the slice to the next lexicographic permutation.

Returns true if successful, false if the slice is at the last-ordered permutation.

Example

fn main() { let v = &mut [0i, 1, 2]; v.next_permutation(); assert_eq!(v, &mut [0i, 2, 1]); v.next_permutation(); assert_eq!(v, &mut [1i, 0, 2]); }
let v = &mut [0i, 1, 2];
v.next_permutation();
assert_eq!(v, &mut [0i, 2, 1]);
v.next_permutation();
assert_eq!(v, &mut [1i, 0, 2]);

fn prev_permutation(self) -> bool

Mutates the slice to the previous lexicographic permutation.

Returns true if successful, false if the slice is at the first-ordered permutation.

Example

fn main() { let v = &mut [1i, 0, 2]; v.prev_permutation(); assert_eq!(v, &mut [0i, 2, 1]); v.prev_permutation(); assert_eq!(v, &mut [0i, 1, 2]); }
let v = &mut [1i, 0, 2];
v.prev_permutation();
assert_eq!(v, &mut [0i, 2, 1]);
v.prev_permutation();
assert_eq!(v, &mut [0i, 1, 2]);

Implementors