Trait gstreamer::prelude::OptionOrd

source ·
pub trait OptionOrd<Rhs, InnerRhs = Rhs> {
    // Required method
    fn opt_cmp(&self, rhs: Rhs) -> Option<Ordering>;

    // Provided methods
    fn opt_lt(&self, rhs: Rhs) -> Option<bool> { ... }
    fn opt_le(&self, rhs: Rhs) -> Option<bool> { ... }
    fn opt_gt(&self, rhs: Rhs) -> Option<bool> { ... }
    fn opt_ge(&self, rhs: Rhs) -> Option<bool> { ... }
}
Expand description

Trait for values and Options that can be compared for a sort-order.

This implementation is mainly intended at working around the PartialOrd implementation for Option, which compares Options depending on the order of declaration in the enum.

§PartialOrd implementation for Option

let some_0 = Some(0);
let none: Option<u64> = None;

assert_eq!(none.partial_cmp(&some_0), Some(Ordering::Less));
assert_eq!(some_0.partial_cmp(&none), Some(Ordering::Greater));

§Alternative behavior

In some cases, we might consider that None reflects a value which is not defined and thus can not be compared with Some(_).

assert_eq!(none.opt_cmp(&some_0), None);
assert_eq!(some_0.opt_cmp(&none), None);

§Implementations

Implementing this type leads to the following auto-implementations:

  • OptionOrd<Option<InnerRhs>> for T.
  • OptionOrd<Rhs> for Option<T>.
  • OptionOrd<Option<InnerRhs>> for Option<T>.
  • … and some variants with references.

This trait is auto-implemented for OptionOperations types implementing PartialOrd<Rhs>.

Required Methods§

source

fn opt_cmp(&self, rhs: Rhs) -> Option<Ordering>

Returns an ordering between self and rhs values if one exists.

Returns None if they can’t be compared, e.g. if at most one argument is None.

Provided Methods§

source

fn opt_lt(&self, rhs: Rhs) -> Option<bool>

Tests whether self is less than rhs.

Returns None if they can’t be compared, e.g. if at most one argument is None.

source

fn opt_le(&self, rhs: Rhs) -> Option<bool>

Tests whether self is less or equal to rhs.

Returns None if they can’t be compared, e.g. if at most one argument is None.

source

fn opt_gt(&self, rhs: Rhs) -> Option<bool>

Tests whether self is greater than rhs.

Returns None if they can’t be compared, e.g. if at most one argument is None.

source

fn opt_ge(&self, rhs: Rhs) -> Option<bool>

Tests whether self is greater or equal to rhs.

Returns None if they can’t be compared, e.g. if at most one argument is None.

Implementations on Foreign Types§

source§

impl<T, InnerRhs> OptionOrd<&Option<InnerRhs>, InnerRhs> for Option<T>
where T: OptionOperations + for<'a> OptionOrd<&'a InnerRhs, InnerRhs>,

source§

fn opt_cmp(&self, rhs: &Option<InnerRhs>) -> Option<Ordering>

source§

impl<T, InnerRhs> OptionOrd<Option<InnerRhs>, InnerRhs> for Option<T>
where T: OptionOperations + for<'a> OptionOrd<&'a InnerRhs, InnerRhs>,

source§

fn opt_cmp(&self, rhs: Option<InnerRhs>) -> Option<Ordering>

source§

impl<T, Rhs> OptionOrd<&Rhs, Rhs> for Option<T>
where T: OptionOperations + for<'a> OptionOrd<&'a Rhs, Rhs>,

source§

fn opt_cmp(&self, rhs: &Rhs) -> Option<Ordering>

source§

impl<T, Rhs> OptionOrd<Rhs> for Option<T>
where T: OptionOperations + for<'a> OptionOrd<&'a Rhs, Rhs>,

source§

fn opt_cmp(&self, rhs: Rhs) -> Option<Ordering>

Implementors§

source§

impl<T, InnerRhs> OptionOrd<&Option<InnerRhs>, InnerRhs> for T
where T: OptionOperations + for<'a> OptionOrd<&'a InnerRhs, InnerRhs>,

source§

impl<T, InnerRhs> OptionOrd<Option<InnerRhs>, InnerRhs> for T
where T: OptionOperations + for<'a> OptionOrd<&'a InnerRhs, InnerRhs>,

source§

impl<T, Rhs> OptionOrd<&Rhs, Rhs> for T
where T: OptionOperations + PartialOrd<Rhs>,

source§

impl<T, Rhs> OptionOrd<Rhs> for T
where T: OptionOperations + for<'a> OptionOrd<&'a Rhs, Rhs>,