[−][src]Function comparator::as_fn
pub fn as_fn<T>(
comparator: impl Comparator<T>
) -> impl Fn(&T, &T) -> Ordering where
T: ?Sized,
Convert a comparator to a comparator function.
This is not a member function, as in stable Rust it's not possible
to implement Fn
trait manually, forcing usage of impl Trait
return type. Currently it is not allowed for trait methods to return
impl Trait
s.
Examples
use comparator::{as_fn, reverse_order}; let mut v = [5, 4, 1, 3, 2]; v.sort_by(as_fn(reverse_order())); assert_eq!(v, [5, 4, 3, 2, 1]);