當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。