Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_core/src/ord.rs

1.1 KiB, 1 run

created by r1870400018:112, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1use std::cmp;
2
3#[derive(Debug, Eq, PartialEq, Copy, Clone)]
4pub enum Relation {
5 Less,
6 Equal,
7 Greater,
8 Complement, // e.g. equal, but opposite
9}
10
11impl Relation {
12
13 pub fn reverse(self) -> Self {
14 match self {
15 Self::Less => Self::Greater,
16 Self::Greater => Self::Less,
17 _ => self,
18 }
19 }
20
21 pub fn ordering(cmp: cmp::Ordering) -> Self {
22 match cmp {
23 cmp::Ordering::Less => Self::Less,
24 cmp::Ordering::Greater => Self::Greater,
25 cmp::Ordering::Equal => Self::Equal,
26 }
27 }
28
29}
30
31#[derive(Clone, Debug)]
32pub struct Ordered<V: Ord + PartialOrd, N: Ord + PartialOrd> {
33 val: V,
34 ord: N,
35}
36
37impl<
38 V: Ord + PartialOrd,
39 N: Ord + PartialOrd,
40>
41 Ordered<V, N>
42{
43 pub fn new(val: V, ord: N) -> Self {
44 Self {
45 val,
46 ord,
47 }
48 }
49}
50
51pub fn ord_string(n: usize) -> String {
52 let suffix = match n % 10 {
53 1 if n % 100 != 11 => "st",
54 2 if n % 100 != 12 => "nd",
55 3 if n % 100 != 13 => "rd",
56 _ => "th",
57 };
58 format!("{}{}", n, suffix)
59}