Trait Sort

Source
pub trait Sort<T: PartialOrd + Clone> {
    // Required methods
    fn inner(&self) -> Vec<T>;
    fn sort_by<F>(&mut self, f: F)
       where F: FnOnce(&T, &T) -> bool + Copy;

    // Provided methods
    fn sort(&mut self) { ... }
    fn is_sort(&self) -> bool { ... }
    fn is_sort_by<F>(&self, f: F) -> bool
       where F: FnOnce(&T, &T) -> bool + Copy { ... }
}
Expand description

Generic interface to sorting algorithms

Required Methods§

Source

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

Get the internal data

Source

fn sort_by<F>(&mut self, f: F)
where F: FnOnce(&T, &T) -> bool + Copy,

Customizable comparison logic based on closures

Provided Methods§

Source

fn sort(&mut self)

Sort by ascending order

Source

fn is_sort(&self) -> bool

Determine if the sort is ascending

Source

fn is_sort_by<F>(&self, f: F) -> bool
where F: FnOnce(&T, &T) -> bool + Copy,

Customized judgments are ordered

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> Sort<T> for MergeSort<T>
where T: PartialOrd + Default + Copy + Infite + Debug,

Source§

impl<T: Clone + PartialOrd> Sort<T> for BubbleSort<T>

Source§

impl<T: PartialOrd + Clone> Sort<T> for InsertSort<T>

Source§

impl<T: PartialOrd + Clone> Sort<T> for SelectSort<T>