malachite_base/bools/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::fmt::{Formatter, Result};
11
12impl ToTypst for bool {
13 /// Writes a [`bool`] as a Typst math-mode fragment.
14 ///
15 /// `true` becomes `"T"` and `false` becomes `"F"`. The quotation marks make them a string,
16 /// which Typst typesets upright, rather than letting them be typeset as italic variables.
17 ///
18 /// # Worst-case complexity
19 /// Constant time and additional memory.
20 ///
21 /// # Examples
22 /// ```
23 /// use malachite_base::strings::typst::ToTypst;
24 ///
25 /// assert_eq!(true.to_typst_string(), r#""T""#);
26 /// assert_eq!(false.to_typst_string(), r#""F""#);
27 /// ```
28 ///
29 /// | value | fragment |
30 /// |---------|----------|
31 /// | `true` | `"T"` |
32 /// | `false` | `"F"` |
33 #[inline]
34 fn fmt_typst(&self, f: &mut Formatter) -> Result {
35 f.write_str(if *self { "\"T\"" } else { "\"F\"" })
36 }
37}