use crate::Rational;
use core::fmt::{Display, Formatter, Result, Write};
use malachite_base::strings::typst::ToTypst;
fn fmt_typst_unsigned(q: &Rational, f: &mut Formatter) -> Result {
let n = q.numerator_ref();
let d = q.denominator_ref();
if *d == 1u32 {
return Display::fmt(n, f);
}
f.write_str("frac(")?;
Display::fmt(n, f)?;
f.write_str(", ")?;
Display::fmt(d, f)?;
f.write_str(")")
}
impl ToTypst for Rational {
#[inline]
fn fmt_typst(&self, f: &mut Formatter) -> Result {
if !self.sign {
f.write_char('-')?;
}
fmt_typst_unsigned(self, f)
}
}