Repository: typst/typst
File: crates/typst-library/src/model/par.rs (Rust)

Code before:
    #[elem]
    type ParLine;
}

/// Configuration for microtypographical settings to be used during
/// justification.
#[derive(Debug, Default, Copy, Clone, PartialEq, Hash)]
pub struct JustificationLimits {
    /// Minimum allowable word spacing.
    pub word_min: Rel,
    /// Maximum allowable word spacing.
    pub word_max: Rel,
    /// Minimum allowable glyph spacing.
    pub glyph_min: Rel,
    /// Maximum allowable glyph spacing.
    pub glyph_max: Rel,
}

cast! {
    JustificationLimits,
    self => Value::Dict(self.into()),
    mut dict: Dict => {
        let mut word: Dict = dict.take("word")?.cast()?;
        let word_min = word.take("min")?.cast()?;
        let word_max = word.take("max")?.cast()?;
word.finish(&["min", "max"])?;

        let mut glyph: Dict = dict.take("glyph")?.cast()?;
        let glyph_min = glyph.take("min")?.cast()?;
        let glyph_max = glyph.take("max")?.cast()?;
glyph.finish(&["min", "max"])?;

        dict.finish(&["word", "glyph"])?;
        Self {
            word_min,
            word_max,
            glyph_min,
            glyph_max
        }
    },
}

impl From<JustificationLimits> for Dict {
    fn from(justification_limits: JustificationLimits) -> Self {
        dict! {
            "word" => dict! {
                "min" => justification_limits.word_min,
                "max" => justification_limits.word_max,
            },
            "glyph" => dict! {
                "min" => justification_limits.glyph_min,

Review comment (suggestion):
```suggestion
        word.finish(&["min", "max"])?;
```

oopsie, forgot to include leading spaces. How did it pass formatting checks though 🤔 same thing below 

Code after:
    /// #set par(justify: true)
    /// #set text(size: 0.8em)
    ///
    /// #grid(
    ///   columns: (1fr, 1fr),
    ///   gutter: 20pt,
    ///   {
    ///     // These are Typst's default limits.
    ///     set par(justification-limits: (
    ///       spacing: (min: 100% * 2 / 3, max: 150%),
    ///       tracking: (min: 0em, max: 0em),
    ///     ))
    ///     example[Word-level justification]
    ///   },
    ///   {
    ///     // These are our custom character-level limits.
    ///     set par(justification-limits: (
    ///       tracking: (min: -0.01em, max: 0.02em),
    ///     ))
    ///     example[Character-level justification]
    ///   },
    /// )
    /// ```
    #[fold]
    pub justification_limits: JustificationLimits,

    /// How to determine line breaks.
    ///
    /// When this property is set to `{auto}`, its default value, optimized line
    /// breaks will be used for justified paragraphs. Enabling optimized line
    /// breaks for ragged paragraphs may also be worthwhile to improve the
    /// appearance of the text.
    ///
    /// ```example
    /// #set page(width: 207pt)
    /// #set par(linebreaks: "simple")
    /// Some texts feature many longer
    /// words. Those are often exceedingly
    /// challenging to break in a visually
    /// pleasing way.
    ///
    /// #set par(linebreaks: "optimized")
    /// Some texts feature many longer
    /// words. Those are often exceedingly
    /// challenging to break in a visually
    /// pleasing way.
    /// ```
    pub linebreaks: Smart<Linebreaks>,

    /// The indent the first line of a paragraph should have.
    ///