当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Rust Ordering.then用法及代码示例


本文简要介绍rust语言中 core::cmp::Ordering.then 的用法。

用法

pub const fn then(self, other: Ordering) -> Ordering

链接两个订单。

当它不是 Equal 时返回 self 。否则返回 other

例子

use std::cmp::Ordering;

let result = Ordering::Equal.then(Ordering::Less);
assert_eq!(result, Ordering::Less);

let result = Ordering::Less.then(Ordering::Equal);
assert_eq!(result, Ordering::Less);

let result = Ordering::Less.then(Ordering::Greater);
assert_eq!(result, Ordering::Less);

let result = Ordering::Equal.then(Ordering::Equal);
assert_eq!(result, Ordering::Equal);

let x: (i64, i64, i64) = (1, 2, 7);
let y: (i64, i64, i64) = (1, 5, 3);
let result = x.0.cmp(&y.0).then(x.1.cmp(&y.1)).then(x.2.cmp(&y.2));

assert_eq!(result, Ordering::Less);

相关用法


注:本文由纯净天空筛选整理自rust-lang.org大神的英文原创作品 core::cmp::Ordering.then。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。