# OrderedComparer

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-reactiveui/comparers/struct-orderedcomparer/

**struct** · [`ferroui-reactiveui`](/docs/0.5.0/api/ferroui-reactiveui/) · v0.5.0

```rust
struct OrderedComparer<T>
```

The starting point of a chain of comparers of `T` (`OrderedComparer<T>` and the non-generic
`OrderedComparer`): the first key of the order, which `then_by` extends.

Deviation (DEVIATIONS.md, ReactiveUI): upstream's generic and non-generic static classes share
the name; here they are the functions of one type, the `For` functions of the non-generic class
being `for_items` and `for_type`. A comparer is a shared
comparison function ([`Comparer`](/docs/0.5.0/api/ferroui-reactiveui/comparers/type_alias-comparer/)), as `IComparer<T>` is in the rest of the port.

```
use ferroui_reactiveui::{ComparerChainingExtensions, OrderedComparer};

let mut words = vec!["bb", "a", "ab", "b"];
let comparer = OrderedComparer::<&str>::order_by(|word| word.len()).then_by(|word| word.to_string());
words.sort_by(|x, y| comparer(x, y));
assert_eq!(words, vec!["a", "b", "ab", "bb"]);
```

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/comparers/ordered_comparer_t.rs#L22)

## Members

- [`for_items`](#function-for_items)
- [`for_type`](#function-for_type)
- [`order_by`](#function-order_by)
- [`order_by_with`](#function-order_by_with)
- [`order_by_descending`](#function-order_by_descending)
- [`order_by_descending_with`](#function-order_by_descending_with)

<a id="function-for_items"></a>

### for_items

```rust
fn for_items(_items: &[T]) -> OrderedComparerTypeWrapper<T>
```

The builder of comparers of the elements of `items`, whose type it infers; useful for the
types that have no name, such as tuples (`For<T>(IEnumerable<T>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/comparers/ordered_comparer.rs#L10)

<a id="function-for_type"></a>

### for_type

```rust
fn for_type() -> OrderedComparerTypeWrapper<T>
```

The builder of comparers of `T` (`For<T>()`). The builder is not a comparer itself: its
`order_by` methods give one.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/comparers/ordered_comparer.rs#L16)

<a id="function-order_by"></a>

### order_by

```rust
fn order_by<V: Ord + 'static>(selector: impl Fn(&T) -> V + 'static) -> Comparer<T>
```

In ascending order of the values of `selector`, compared by their `Ord`
(`OrderBy<TValue>(Func<T, TValue>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/comparers/ordered_comparer_t.rs#L27)

<a id="function-order_by_with"></a>

### order_by_with

```rust
fn order_by_with<V: 'static>(selector: impl Fn(&T) -> V + 'static, comparer: Comparer<V>) -> Comparer<T>
```

In ascending order of the values of `selector`, compared by `comparer`
(`OrderBy<TValue>(Func<T, TValue>, IComparer<TValue>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/comparers/ordered_comparer_t.rs#L33)

<a id="function-order_by_descending"></a>

### order_by_descending

```rust
fn order_by_descending<V: Ord + 'static>(selector: impl Fn(&T) -> V + 'static) -> Comparer<T>
```

In descending order of the values of `selector`, compared by their `Ord`
(`OrderByDescending<TValue>(Func<T, TValue>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/comparers/ordered_comparer_t.rs#L39)

<a id="function-order_by_descending_with"></a>

### order_by_descending_with

```rust
fn order_by_descending_with<V: 'static>(selector: impl Fn(&T) -> V + 'static, comparer: Comparer<V>) -> Comparer<T>
```

In descending order of the values of `selector`, compared by `comparer`
(`OrderByDescending<TValue>(Func<T, TValue>, IComparer<TValue>)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/comparers/ordered_comparer_t.rs#L45)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
