Repository: alacritty/alacritty
File: alacritty/src/renderer/platform.rs (Rust)

Code before:
    ContextApi, ContextAttributesBuilder, GlProfile, NotCurrentContext, Version,
};
use glutin::display::{Display, DisplayApiPreference, GetGlDisplay};
use glutin::error::Result as GlutinResult;
use glutin::prelude::*;
use glutin::surface::{Surface, SurfaceAttributesBuilder, WindowSurface};
use log::{debug, LevelFilter};

use raw_window_handle::{RawDisplayHandle, RawWindowHandle};
use winit::dpi::PhysicalSize;
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
use winit::platform::x11;

/// Create the GL display.
pub fn create_gl_display(
    raw_display_handle: RawDisplayHandle,
    _raw_window_handle: Option<RawWindowHandle>,
) -> GlutinResult<Display> {
    #[cfg(target_os = "macos")]
    let preference = DisplayApiPreference::Cgl;

    #[cfg(windows)]
    let preference = match env::var("PREFER_EGL") {
        Ok(egl) if egl == "1" => {
            DisplayApiPreference::EglThenWgl(Some(_raw_window_handle.unwrap()))
        },
        _ => DisplayApiPreference::Wgl(Some(_raw_window_handle.unwrap())),
    };

    #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
    let preference = match env::var("PREFER_EGL") {
        Ok(egl) if egl == "1" => {
            DisplayApiPreference::EglThenGlx(Box::new(x11::register_xlib_error_hook))
        },
        _ => DisplayApiPreference::GlxThenEgl(Box::new(x11::register_xlib_error_hook)),
    };

    #[cfg(all(not(feature = "x11"), not(any(target_os = "macos", windows))))]
    let preference = DisplayApiPreference::Egl;

    let display = unsafe { Display::new(raw_display_handle, preference)? };
    log::info!("Using {}", { display.version_string() });
    Ok(display)
}

pub fn pick_gl_config(
    gl_display: &Display,
    raw_window_handle: Option<RawWindowHandle>,
) -> Result<Config, String> {
    let mut default_config = ConfigTemplateBuilder::new()
        .with_depth_size(0)

Review comment (suggestion):
You can do something like that to match directly without `if`.

```rust
    #[cfg(windows)]
    let preference = match std::env::var("PREFER_EGL").as_ref().map(|s| s.as_str()) {
        Ok("1") => DisplayApiPreference::EglThenWgl(Some(_raw_window_handle.unwrap())),
        _ => DisplayApiPreference::Wgl(Some(_raw_window_handle.unwrap())),
    };

```

Code after:
use glutin::display::{Display, DisplayApiPreference, GetGlDisplay};
use glutin::error::Result as GlutinResult;
use glutin::prelude::*;
use glutin::surface::{Surface, SurfaceAttributesBuilder, WindowSurface};
use log::{debug, LevelFilter};

use winit::dpi::PhysicalSize;
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
use winit::platform::x11;
use winit::window::raw_window_handle::{RawDisplayHandle, RawWindowHandle};

/// Create the GL display.
pub fn create_gl_display(
    raw_display_handle: RawDisplayHandle,
    _raw_window_handle: Option<RawWindowHandle>,
    _prefer_egl: bool,
) -> GlutinResult<Display> {
    #[cfg(target_os = "macos")]
    let preference = DisplayApiPreference::Cgl;

    #[cfg(windows)]
    let preference = if _prefer_egl {
        DisplayApiPreference::EglThenWgl(Some(_raw_window_handle.unwrap()))
    } else {
        DisplayApiPreference::WglThenEgl(Some(_raw_window_handle.unwrap()))
    };

    #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
    let preference = if _prefer_egl {
        DisplayApiPreference::EglThenGlx(Box::new(x11::register_xlib_error_hook))
    } else {
        DisplayApiPreference::GlxThenEgl(Box::new(x11::register_xlib_error_hook))
    };

    #[cfg(all(not(feature = "x11"), not(any(target_os = "macos", windows))))]
    let preference = DisplayApiPreference::Egl;

    let display = unsafe { Display::new(raw_display_handle, preference)? };
    log::info!("Using {}", { display.version_string() });
    Ok(display)
}

pub fn pick_gl_config(
    gl_display: &Display,
    raw_window_handle: Option<RawWindowHandle>,
) -> Result<Config, String> {
    let mut default_config = ConfigTemplateBuilder::new()
        .with_depth_size(0)
        .with_stencil_size(0)
        .with_transparency(true);