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

Code before:
/// 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,
                "max" => justification_limits.glyph_max,
            },
        }
    }
}

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

same thing as above with `word.finish`

Code after:
    ///   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.
    ///
    /// By default, only the first line of a consecutive paragraph will be
    /// indented (not the first one in the document or container, and not
    /// paragraphs immediately following other block-level elements).
    ///
    /// If you want to indent all paragraphs instead, you can pass a dictionary