Repository: alacritty/alacritty
File: font/src/ft/mod.rs (Rust)

Code before:

                let _ = coverage.merge(&charset);

                FallbackFont::new(fallback_font, fallback_font_key)
            })
            .collect();

        self.fallback_lists.insert(font_key, FallbackList { list, coverage });

        Ok(font_key)
    }

    fn full_metrics(&self, face_load_props: &FaceLoadingProperties) -> Result<FullMetrics, Error> {
        let size_metrics =
            face_load_props.ft_face.size_metrics().ok_or(Error::MissingSizeMetrics)?;

        let width =
            match face_load_props.ft_face.load_char('0' as usize, face_load_props.load_flags) {
                Ok(_) => face_load_props.ft_face.glyph().metrics().horiAdvance / 64,
                Err(_) => size_metrics.max_advance / 64,
            } as f64;

        Ok(FullMetrics { size_metrics, cell_width: width })
    }

    fn load_ft_face(&mut self, path: PathBuf, index: isize) -> Result<Rc<FTFace>, Error> {
        let mut ft_face = self.library.new_face(&path, index)?;
        if ft_face.has_color() {
            unsafe {
                // Select the colored bitmap size to use from the array of available sizes
                freetype_sys::FT_Select_Size(ft_face.raw_mut(), 0);
            }
        }

        let ft_face = Rc::new(ft_face);
        self.ft_faces.insert(path, Rc::downgrade(&ft_face));

        Ok(ft_face)
    }

    fn face_from_pattern(
        &mut self,
        pattern: &PatternRef,
        font_key: FontKey,
    ) -> Result<Option<FontKey>, Error> {
        if let (Some(path), Some(index)) = (pattern.file(0), pattern.index().next()) {
            if self.faces.get(&font_key).is_some() {
                return Ok(Some(font_key));
            }

            trace!("Got font path={:?}", path);

Review comment (refactor):
Might be worth to extract `face_load_props.ft_face` into a variable here, since it would prevent two very ugly linebreaks.

Code after:
    fn full_metrics(&self, face_load_props: &FaceLoadingProperties) -> Result<FullMetrics, Error> {
        let ft_face = &face_load_props.ft_face;
        let size_metrics = ft_face.size_metrics().ok_or(Error::MissingSizeMetrics)?;

        let width = match ft_face.load_char('0' as usize, face_load_props.load_flags) {
            Ok(_) => ft_face.glyph().metrics().horiAdvance / 64,
            Err(_) => size_metrics.max_advance / 64,
        } as f64;

        Ok(FullMetrics { size_metrics, cell_width: width })
    }

    fn load_ft_face(&mut self, path: PathBuf, index: isize) -> Result<Rc<FTFace>, Error> {
        let mut ft_face = self.library.new_face(&path, index)?;
        if ft_face.has_color() {
            unsafe {
                // Select the colored bitmap size to use from the array of available sizes
                freetype_sys::FT_Select_Size(ft_face.raw_mut(), 0);
            }
        }

        let ft_face = Rc::new(ft_face);
        self.ft_faces.insert(path, Rc::clone(&ft_face));

        Ok(ft_face)
    }

    fn face_from_pattern(
        &mut self,
        pattern: &PatternRef,
        font_key: FontKey,
    ) -> Result<Option<FontKey>, Error> {
        if let (Some(path), Some(index)) = (pattern.file(0), pattern.index().next()) {
            if self.faces.get(&font_key).is_some() {
                return Ok(Some(font_key));
            }

            trace!("Got font path={:?}", path);

            let ft_face = match self.ft_faces.get(&path) {
                Some(ft_face) => Rc::clone(ft_face),
                None => self.load_ft_face(path, index)?,
            };

            // Get available pixel sizes if font isn't scalable.
            let pixelsize =
                pattern.pixelsize().next().expect("Font is missing pixelsize information.");

            let pixelsize_fixup_factor = pattern.pixelsizefixupfactor().next();

            let face = FaceLoadingProperties {