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

Code before:
            .0
            .into_iter()
            .map(|setting| FontVariation {
                tag: setting.tag.0,
                value: setting.value,
            })
            .collect();
        let synthesis_weight = style.clone_font_synthesis_weight();
        FontDescriptor {
            weight: style.font_weight,
            stretch: style.font_stretch,
            style: style.font_style,
            variant: style.font_variant_caps,
            pt_size: Au::from_f32_px(style.font_size.computed_size().px()),
            variation_settings,
            synthesis_weight,
        }
    }
}

impl FontDescriptor {
    pub fn with_variation_settings(&self, variation_settings: Vec<FontVariation>) -> Self {
        FontDescriptor {
            weight: self.weight,
            stretch: self.stretch,
            style: self.style,
            variant: self.variant,
            pt_size: self.pt_size,
            variation_settings,
            synthesis_weight: self.synthesis_weight,
        }
    }
}

/// A version of `FontStyle` from Stylo that is serializable. Normally this is not
/// because the specified version of `FontStyle` contains floats.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum ComputedFontStyleDescriptor {
    Italic,
    Oblique(FontStyleFixedPoint, FontStyleFixedPoint),
}

/// This data structure represents the various optional descriptors that can be
/// applied to a `@font-face` rule in CSS. These are used to create a [`FontTemplate`]
/// from the given font data used as the source of the `@font-face` rule. If values
/// like weight, stretch, and style are not specified they are initialized based
/// on the contents of the font itself.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CSSFontFaceDescriptors {
    pub family_name: LowercaseFontFamilyName,
    pub weight: Option<(FontWeight, FontWeight)>,

Review comment (suggestion):
Does the following work perhaps?

```suggestion
        FontDescriptor {
             variation_settings,
             ..self
        }
```

Code after:
            .0
            .into_iter()
            .map(|setting| FontVariation {
                tag: setting.tag.0,
                value: setting.value,
            })
            .collect();
        let synthesis_weight = style.clone_font_synthesis_weight();
        FontDescriptor {
            weight: style.font_weight,
            stretch: style.font_stretch,
            style: style.font_style,
            variant: style.font_variant_caps,
            pt_size: Au::from_f32_px(style.font_size.computed_size().px()),
            variation_settings,
            synthesis_weight,
        }
    }
}

impl FontDescriptor {
    pub fn with_variation_settings(&self, variation_settings: Vec<FontVariation>) -> Self {
        FontDescriptor {
            variation_settings,
            ..*self
        }
    }
}

/// A version of `FontStyle` from Stylo that is serializable. Normally this is not
/// because the specified version of `FontStyle` contains floats.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum ComputedFontStyleDescriptor {
    Italic,
    Oblique(FontStyleFixedPoint, FontStyleFixedPoint),
}

/// This data structure represents the various optional descriptors that can be
/// applied to a `@font-face` rule in CSS. These are used to create a [`FontTemplate`]
/// from the given font data used as the source of the `@font-face` rule. If values
/// like weight, stretch, and style are not specified they are initialized based
/// on the contents of the font itself.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct CSSFontFaceDescriptors {
    pub family_name: LowercaseFontFamilyName,
    pub weight: Option<(FontWeight, FontWeight)>,
    pub stretch: Option<(FontStretch, FontStretch)>,
    pub style: Option<ComputedFontStyleDescriptor>,
    pub unicode_range: Option<Vec<RangeInclusive<u32>>>,
}