blob: a11f30388adef33ec17e084c46af9a23d89032e3 [file] [log] [blame]
use crate::swapper::Swapper;
use core::{mem, ptr};
use std::cmp::min;
pub struct LoopSwapper {}
impl Swapper for LoopSwapper {
fn swap<T>(a: &mut [T], b: &mut [T]) {
for (x, y) in a.iter_mut().zip(b.iter_mut()) {
mem::swap(x, y);
}
}
}
pub struct PtrSwapper {}
impl Swapper for PtrSwapper {
fn swap<T>(a: &mut [T], b: &mut [T]) {
unsafe { ptr::swap_nonoverlapping(a.as_mut_ptr(), b.as_mut_ptr(), min(a.len(), b.len())) }
}
}