Trait swap3::Swap3

source ·
pub trait Swap3<I = usize> {
    // Required methods
    fn swap3_bca(&mut self, a: I, b: I, c: I);
    fn swap3_cab(&mut self, a: I, b: I, c: I);
}
Expand description

Trait providing the Swap3::swap3_bca and Swap3::swap3_cab functions directly.

Required Methods§

source

fn swap3_bca(&mut self, a: I, b: I, c: I)

Rotates three values to the left.

§Arguments
  • a - The first index, to be assigned with the value of data[b].
  • b - The second index, to be assigned with the value of data[c].
  • c - The third index, to be assigned with the value of data[a].
§Example
use swap3::prelude::*;
let mut vec = vec![50, 10, 90, 25, 30, 75];
vec.swap3_bca(0, 1, 4);
assert_eq!(vec, &[10, 30, 90, 25, 50, 75]);
source

fn swap3_cab(&mut self, a: I, b: I, c: I)

Rotates three values to the right.

§Arguments
  • a - The first index, to be assigned with the value of data[c].
  • b - The second index, to be assigned with the value of data[a].
  • c - The third index, to be assigned with the value of data[b].
§Example
use swap3::prelude::*;
let mut vec = vec![50, 10, 90, 25, 30, 75];
vec.swap3_cab(0, 1, 4);
assert_eq!(vec, &[30, 50, 90, 25, 10, 75]);

Implementations on Foreign Types§

source§

impl<T> Swap3 for [T]

source§

fn swap3_bca(&mut self, a: usize, b: usize, c: usize)

source§

fn swap3_cab(&mut self, a: usize, b: usize, c: usize)

Implementors§