use crate::strings::typst::ToTypst;
use core::fmt::{Formatter, Result};
pub(crate) fn fmt_typst_sequence<'a, T: ToTypst + 'a>(
xs: impl Iterator<Item = &'a T>,
open: &str,
close: &str,
f: &mut Formatter,
) -> Result {
f.write_str(open)?;
for (i, x) in xs.enumerate() {
if i != 0 {
f.write_str(", ")?;
}
x.fmt_typst(f)?;
}
f.write_str(close)
}
pub(crate) fn fmt_typst_slice<T: ToTypst>(xs: &[T], f: &mut Formatter) -> Result {
fmt_typst_sequence(xs.iter(), "[", "]", f)
}
impl<T: ToTypst> ToTypst for &[T] {
#[inline]
fn fmt_typst(&self, f: &mut Formatter) -> Result {
fmt_typst_slice(self, f)
}
}
impl<T: ToTypst, const N: usize> ToTypst for [T; N] {
#[inline]
fn fmt_typst(&self, f: &mut Formatter) -> Result {
fmt_typst_slice(self, f)
}
}