Repository: servo/servo
File: components/layout/flow/inline/text_run.rs (Rust)

Code before:
///
/// <https://www.w3.org/TR/css-display-3/#css-text-run>
#[derive(Debug, MallocSizeOf)]
pub(crate) struct TextRun {
    /// The [`BaseFragmentInfo`] for this [`TextRun`]. Usually this comes from the
    /// original text node in the DOM for the text.
    pub base_fragment_info: BaseFragmentInfo,

    /// The [`crate::SharedStyle`] from this [`TextRun`]s parent element. This is
    /// shared so that incremental layout can simply update the parent element and
    /// this [`TextRun`] will be updated automatically.
    pub inline_styles: SharedInlineStyles,

    /// The range of text in [`super::InlineFormattingContext::text_content`] of the
    /// [`super::InlineFormattingContext`] that owns this [`TextRun`]. These are UTF-8 offsets.
    pub text_range: Range<usize>,

    /// The text of this [`TextRun`] with a font selected, broken into unbreakable
    /// segments, and shaped.
    pub shaped_text: Vec<TextRunSegment>,

    /// The selection range for the DOM text node that originated this [`TextRun`]. This
    /// comes directly from the DOM.
    pub selection_range: Option<TextByteRange>,

    pub parent_box: Option<WeakLayoutBox>,
}

impl TextRun {
    pub(crate) fn new(
        base_fragment_info: BaseFragmentInfo,
        inline_styles: SharedInlineStyles,
        text_range: Range<usize>,
        selection_range: Option<TextByteRange>,
    ) -> Self {
        Self {
            base_fragment_info,
            inline_styles,
            text_range,
            shaped_text: Vec::new(),
            selection_range,
            parent_box: None,
        }
    }

    pub(super) fn segment_and_shape(
        &mut self,
        formatting_context_text: &str,
        layout_context: &LayoutContext,
        linebreaker: &mut LineBreaker,
        bidi_info: &BidiInfo,

Review comment (suggestion):
Let's put this add the to of the struct since it's of about the structure of the tree
```suggestion

    /// A weak reference to the parent of this layout box. This becomes valid as soon
    /// as the *parent* of this box is added to the tree.
    pub parent_box: Option<WeakLayoutBox>,
```

Code after:
///
/// <https://www.w3.org/TR/css-display-3/#css-text-run>
#[derive(Debug, MallocSizeOf)]
pub(crate) struct TextRun {
    /// The [`BaseFragmentInfo`] for this [`TextRun`]. Usually this comes from the
    /// original text node in the DOM for the text.
    pub base_fragment_info: BaseFragmentInfo,

    /// A weak reference to the parent of this layout box. This becomes valid as soon
    /// as the *parent* of this box is added to the tree.
    pub parent_box: Option<WeakLayoutBox>,

    /// The [`crate::SharedStyle`] from this [`TextRun`]s parent element. This is
    /// shared so that incremental layout can simply update the parent element and
    /// this [`TextRun`] will be updated automatically.
    pub inline_styles: SharedInlineStyles,

    /// The range of text in [`super::InlineFormattingContext::text_content`] of the
    /// [`super::InlineFormattingContext`] that owns this [`TextRun`]. These are UTF-8 offsets.
    pub text_range: Range<usize>,

    /// The text of this [`TextRun`] with a font selected, broken into unbreakable
    /// segments, and shaped.
    pub shaped_text: Vec<TextRunSegment>,

    /// The selection range for the DOM text node that originated this [`TextRun`]. This
    /// comes directly from the DOM.
    pub selection_range: Option<TextByteRange>,
}

impl TextRun {
    pub(crate) fn new(
        base_fragment_info: BaseFragmentInfo,
        inline_styles: SharedInlineStyles,
        text_range: Range<usize>,
        selection_range: Option<TextByteRange>,
    ) -> Self {
        Self {
            base_fragment_info,
            parent_box: None,
            inline_styles,
            text_range,
            shaped_text: Vec::new(),
            selection_range,
        }
    }

    pub(super) fn segment_and_shape(
        &mut self,
        formatting_context_text: &str,
        layout_context: &LayoutContext,