Repository: servo/servo
File: components/shared/fonts/font_template.rs (Rust)

Code before:
    }
}

/// Data for a font load operation initiated by a `@font-face` rule.
#[derive(Clone, MallocSizeOf)]
pub struct FontFaceRuleInitiator {
    pub stylesheet: DocumentStyleSheet,
    #[ignore_malloc_size_of = "TODO"]
    pub font_face_rule: FontFaceRule,
}

/// This describes all the information needed to create
/// font instance handles. It contains a unique
/// FontTemplateData structure that is platform specific.
#[derive(Clone, Deserialize, MallocSizeOf, Serialize)]
pub struct FontTemplate {
    pub identifier: FontIdentifier,
    pub descriptor: FontTemplateDescriptor,
    /// If this font is a web font, this is a reference to the stylesheet that
    /// created it. This will be used to remove this font from caches, when the
    /// stylesheet is removed.
    ///
    /// This is not serialized, as it's only useful in the [`super::FontContext`]
    /// that it is created in.
    #[serde(skip)]
    font_face_rule: Option<FontFaceRuleInitiator>,
}

impl Debug for FontTemplate {
    fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
        self.identifier.fmt(f)
    }
}

/// Holds all of the template information for a font that
/// is common, regardless of the number of instances of
/// this font handle per thread.
impl FontTemplate {
    /// Create a new [`FontTemplate`].
    pub fn new(
        identifier: FontIdentifier,
        descriptor: FontTemplateDescriptor,
        font_face_rule: Option<FontFaceRuleInitiator>,
    ) -> FontTemplate {
        FontTemplate {
            identifier,
            descriptor,
            font_face_rule,
        }
    }


Review comment (suggestion):
Please store these two types separately, as I think they both deserve their own fields and rustdoc. The rustdoc here is now out of date, but wouldn't be if you just add another member called `font_face_rule`.

Code after:
        }
    }
}

/// This describes all the information needed to create
/// font instance handles. It contains a unique
/// FontTemplateData structure that is platform specific.
#[derive(Clone, Deserialize, MallocSizeOf, Serialize)]
pub struct FontTemplate {
    pub identifier: FontIdentifier,
    pub descriptor: FontTemplateDescriptor,
    /// If this font is a web font, this is a reference to the stylesheet that
    /// created it. This will be used to remove this font from caches, when the
    /// stylesheet is removed.
    ///
    /// This is not serialized, as it's only useful in the [`super::FontContext`]
    /// that it is created in.
    #[serde(skip)]
    pub stylesheet: Option<DocumentStyleSheet>,

    /// If this font is a web font, this is a reference to the `@font-face` rule that
    /// created it.
    #[serde(skip)]
    pub font_face_rule: Option<FontFaceRule>,
}

impl Debug for FontTemplate {
    fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
        self.identifier.fmt(f)
    }
}

/// Holds all of the template information for a font that
/// is common, regardless of the number of instances of
/// this font handle per thread.
impl FontTemplate {
    /// Create a new [`FontTemplate`].
    pub fn new(
        identifier: FontIdentifier,
        descriptor: FontTemplateDescriptor,
        stylesheet: Option<DocumentStyleSheet>,
        font_face_rule: Option<FontFaceRule>,
    ) -> FontTemplate {
        assert!(
            (stylesheet.is_some() && font_face_rule.is_some()) ||
                (stylesheet.is_none() && font_face_rule.is_none())
        );
        FontTemplate {
            identifier,
            descriptor,
            stylesheet,