-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Description
This seems like an obvious and missing function from std::cmp::Ordering
:
impl Ordering {
pub fn then(self, other: Ordering) -> Ordering {
match self {
Ordering::Equal => other,
o => o,
}
}
pub fn and_then<F: FnOnce() -> Ordering>(self, other: F) -> Ordering {
match self {
Ordering::Equal => other(),
o => o,
}
}
}
This is useful for creating comparators which do lexicographic order. The second variant allows for skipping the order calculation if it is not necessary. Names are of course open to bikeshedding.
pmarcelll and killercup
Metadata
Metadata
Assignees
Labels
C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.