Struct Order

Source
pub struct Order<'x, T> { /* private fields */ }

Implementations§

Source§

impl<'x, T> Order<'x, T>

Source

pub fn new(a: &'x T, b: &'x T) -> Self

Source

pub fn by<F>(self, f: F) -> Self
where F: FnMut(&T, &T) -> Ordering,

Source

pub fn reverse_by<F>(self, f: F) -> Self
where F: FnMut(&T, &T) -> Ordering,

Source

pub fn by_key<F, U>(self, f: F) -> Self
where F: FnMut(&T) -> U, U: Ord,

Source

pub fn reverse_by_key<F, U>(self, f: F) -> Self
where F: FnMut(&T) -> U, U: Ord,

Examples found in repository?
examples/people.rs (line 17)
3fn main() {
4    let mut people = vec![
5        // Please PR better a better example if you can think of one 😅
6        Person::new("Michael", "Foo", 24),
7        Person::new("Michael", "Foo", 10),
8        Person::new("Jeff", "Bar", 25),
9        Person::new("Maria", "Foo", 25),
10        Person::new("Maria", "Bar", 26),
11    ];
12
13    #[rustfmt::skip]
14    people.rearrange(|order| order
15        .by_ref(|p| &p.last_name)
16        .by_ref(|p| &p.first_name)
17        .reverse_by_key(|p| p.age)
18    );
19
20    for person in people {
21        println!(
22            "{} {} ({})",
23            person.first_name, person.last_name, person.age
24        );
25    }
26}
Source

pub fn by_ref<F, U>(self, f: F) -> Self
where F: FnMut(&T) -> &U, U: Ord,

Examples found in repository?
examples/people.rs (line 15)
3fn main() {
4    let mut people = vec![
5        // Please PR better a better example if you can think of one 😅
6        Person::new("Michael", "Foo", 24),
7        Person::new("Michael", "Foo", 10),
8        Person::new("Jeff", "Bar", 25),
9        Person::new("Maria", "Foo", 25),
10        Person::new("Maria", "Bar", 26),
11    ];
12
13    #[rustfmt::skip]
14    people.rearrange(|order| order
15        .by_ref(|p| &p.last_name)
16        .by_ref(|p| &p.first_name)
17        .reverse_by_key(|p| p.age)
18    );
19
20    for person in people {
21        println!(
22            "{} {} ({})",
23            person.first_name, person.last_name, person.age
24        );
25    }
26}
Source

pub fn reverse_by_ref<F, U>(self, f: F) -> Self
where F: FnMut(&T) -> &U, U: Ord,

Source

pub fn ordering(&self) -> Ordering

Auto Trait Implementations§

§

impl<'x, T> Freeze for Order<'x, T>

§

impl<'x, T> RefUnwindSafe for Order<'x, T>
where T: RefUnwindSafe,

§

impl<'x, T> Send for Order<'x, T>
where T: Sync,

§

impl<'x, T> Sync for Order<'x, T>
where T: Sync,

§

impl<'x, T> Unpin for Order<'x, T>

§

impl<'x, T> UnwindSafe for Order<'x, T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.