Skip to main content

malachite_base/vecs/
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::slices::typst::fmt_typst_slice;
10use crate::strings::typst::ToTypst;
11use alloc::vec::Vec;
12use core::fmt::{Formatter, Result};
13
14impl<T: ToTypst> ToTypst for Vec<T> {
15    /// Writes a [`Vec`] as a Typst math-mode fragment.
16    ///
17    /// This is the same as the slice implementation.
18    ///
19    /// # Worst-case complexity
20    /// $T(n) = O(n + \sum_{i=0}^{n-1}T^\prime(i))$
21    ///
22    /// $M(n) = O(\max_{i=0}^{n-1}M^\prime(i))$
23    ///
24    /// where $T$ is time, $M$ is additional memory, $n$ is `self.len()`, $i$ is an element's index,
25    /// and $T^\prime$ and $M^\prime$ are the time and memory functions of `fmt_typst` for `T`.
26    ///
27    /// # Examples
28    /// ```
29    /// use malachite_base::strings::typst::ToTypst;
30    ///
31    /// assert_eq!(Vec::<u8>::new().to_typst_string(), "[]");
32    /// assert_eq!(vec![5u8].to_typst_string(), "[5]");
33    /// assert_eq!(vec![1u8, 2, 3].to_typst_string(), "[1, 2, 3]");
34    /// assert_eq!(
35    ///     vec![vec![1u8], vec![2, 3]].to_typst_string(),
36    ///     "[[1], [2, 3]]"
37    /// );
38    /// ```
39    ///
40    /// | value                         | fragment        |
41    /// |-------------------------------|-----------------|
42    /// | `Vec::<u8>::new()`            | `[]`            |
43    /// | `vec![5u8]`                   | `[5]`           |
44    /// | `vec![1u8, 2, 3]`             | `[1, 2, 3]`     |
45    /// | `vec![vec![1u8], vec![2, 3]]` | `[[1], [2, 3]]` |
46    #[inline]
47    fn fmt_typst(&self, f: &mut Formatter) -> Result {
48        fmt_typst_slice(self, f)
49    }
50}