malachite_base/orderings/typst.rs
1// Copyright © 2026 Mikhail Hogrefe
2//
3// This file is part of Malachite.
4//
5// Malachite is free software: you can redistribute it and/or modify it under the terms of the GNU
6// Lesser General Public License (LGPL) as published by the Free Software Foundation; either version
7// 3 of the License, or (at your option) any later version. See <https://www.gnu.org/licenses/>.
8
9use crate::strings::typst::ToTypst;
10use core::cmp::Ordering::{self, *};
11use core::fmt::{Formatter, Result};
12
13impl ToTypst for Ordering {
14 /// Writes an [`Ordering`] as a Typst math-mode fragment.
15 ///
16 /// The three orderings become the three relations they stand for: `<`, `=`, and `>`.
17 ///
18 /// # Worst-case complexity
19 /// Constant time and additional memory.
20 ///
21 /// # Examples
22 /// ```
23 /// use malachite_base::strings::typst::ToTypst;
24 /// use std::cmp::Ordering::*;
25 ///
26 /// assert_eq!(Less.to_typst_string(), "<");
27 /// assert_eq!(Equal.to_typst_string(), "=");
28 /// assert_eq!(Greater.to_typst_string(), ">");
29 /// ```
30 ///
31 /// | value | fragment |
32 /// |-----------|----------|
33 /// | `Less` | `<` |
34 /// | `Equal` | `=` |
35 /// | `Greater` | `>` |
36 #[inline]
37 fn fmt_typst(&self, f: &mut Formatter) -> Result {
38 f.write_str(match self {
39 Less => "<",
40 Equal => "=",
41 Greater => ">",
42 })
43 }
44}