Repository: servo/servo
File: components/fonts/platform/macos/core_text_font_cache.rs (Rust)

Code before:
                    })
                    .unwrap_or(variation.default_value)
                    .clamp(variation.min_value, variation.max_value);
                if value != variation.default_value {
                    modified_variations = true;
                }
                FontVariation {
                    tag: variation.tag as u32,
                    value: value as f32,
                }
            })
            .collect();

        if !modified_variations {
            return platform_font;
        }

        let variation_keys: Vec<_> = variations
            .iter()
            .map(|variation| CFNumber::new_i64(variation.tag as i64))
            .collect();
        let variation_values: Vec<_> = variations
            .iter()
            .map(|variation| CFNumber::new_f32(variation.value))
            .collect();
        let values_dict: CFRetained<CFDictionary<CFNumber, CFNumber>> = CFDictionary::from_slices(
            &variation_keys
                .iter()
                .map(CFRetained::as_ref)
                .collect::<Vec<_>>(),
            &variation_values
                .iter()
                .map(CFRetained::as_ref)
                .collect::<Vec<_>>(),
        );

        let attributes: CFRetained<CFDictionary<CFString, CFType>> = CFDictionary::from_slices(
            &[unsafe { kCTFontVariationAttribute }],
            &[values_dict.as_ref()],
        );
        let descriptor_with_variations = unsafe {
            platform_font
                .ctfont
                .font_descriptor()
                .copy_with_attributes(attributes.as_opaque())
        };

        let ctfont = unsafe {
            CTFont::with_font_descriptor(&descriptor_with_variations, pt_size, std::ptr::null())
        };
        PlatformFont::new_with_ctfont_and_variations(ctfont, variations, synthetic_bold)

Review comment (suggestion):
FYI, I tend to prefer:
```suggestion
        let values_dict = CFDictionary::<CFNumber, CFNumber>::from_slices(
```

It makes it a bit easier on the eyes.

Code after:
                    })
                    .unwrap_or(variation.default_value)
                    .clamp(variation.min_value, variation.max_value);
                if value != variation.default_value {
                    modified_variations = true;
                }
                FontVariation {
                    tag: variation.tag as u32,
                    value: value as f32,
                }
            })
            .collect();

        if !modified_variations {
            return platform_font;
        }

        let variation_keys: Vec<_> = variations
            .iter()
            .map(|variation| CFNumber::new_i64(variation.tag as i64))
            .collect();
        let variation_values: Vec<_> = variations
            .iter()
            .map(|variation| CFNumber::new_f32(variation.value))
            .collect();
        let values_dict = CFDictionary::<CFNumber, CFNumber>::from_slices(
            &variation_keys
                .iter()
                .map(CFRetained::as_ref)
                .collect::<Vec<_>>(),
            &variation_values
                .iter()
                .map(CFRetained::as_ref)
                .collect::<Vec<_>>(),
        );

        let attributes = CFDictionary::<CFString, CFType>::from_slices(
            &[unsafe { kCTFontVariationAttribute }],
            &[values_dict.as_ref()],
        );
        let descriptor_with_variations = unsafe {
            platform_font
                .ctfont
                .font_descriptor()
                .copy_with_attributes(attributes.as_opaque())
        };

        let ctfont = unsafe {
            CTFont::with_font_descriptor(&descriptor_with_variations, pt_size, std::ptr::null())
        };
        PlatformFont::new_with_ctfont_and_variations(ctfont, variations, synthetic_bold)