https://doc.rust-lang.org/std/cmp/index.html

std::cmp - Rust

Expand description

Utilities for comparing and ordering values.

This module contains various tools for comparing and ordering values. In summary:

  • PartialEq<Rhs> overloads the == and != operators. In cases where Rhs (the right hand side’s type) is Self, this trait corresponds to a partial equivalence relation.
  • Eq indicates that the overloaded == operator corresponds to an equivalence relation.
  • Ord and PartialOrd are traits that allow you to define total and partial orderings between values, respectively. Implementing them overloads the <, <=, >, and >= operators.
  • Ordering is an enum returned by the main functions of Ord and PartialOrd, and describes an ordering of two values (less, equal, or greater).
  • Reverse is a struct that allows you to easily reverse an ordering.
  • max and min are functions that build off of Ord and allow you to find the maximum or minimum of two values.

For more details, see the respective documentation of each item in the list.

ReverseA helper struct for reverse ordering.OrderingAn Ordering is the result of a comparison between two values.EqTrait for comparisons corresponding to equivalence relations.OrdTrait for types that form a total order.PartialEqTrait for comparisons using the equality operator.PartialOrdTrait for types that form a partial order.maxCompares and returns the maximum of two values.max_byReturns the maximum of two values with respect to the specified comparison function.max_by_keyReturns the element that gives the maximum value from the specified function.minCompares and returns the minimum of two values.min_byReturns the minimum of two values with respect to the specified comparison function.min_by_keyReturns the element that gives the minimum value from the specified function.minmax ExperimentalCompares and sorts two values, returning minimum and maximum.minmax_by ExperimentalReturns minimum and maximum values with respect to the specified comparison function.minmax_by_key ExperimentalReturns minimum and maximum values with respect to the specified key function.EqDerive macro generating an impl of the trait Eq.OrdDerive macro generating an impl of the trait Ord. The behavior of this macro is described in detail here.PartialEqDerive macro generating an impl of the trait PartialEq. The behavior of this macro is described in detail here.PartialOrdDerive macro generating an impl of the trait PartialOrd. The behavior of this macro is described in detail here.