From 02afe68342870ce4f37d7e8fb45c985397d6e08d Mon Sep 17 00:00:00 2001 From: HampusM Date: Sat, 23 May 2026 19:46:46 +0200 Subject: refactor(engine): use Rust edition 2021 This change is because of a rustfmt bug in the 2024 edition. For example, the following code snippet: ``` struct Value {} struct ParsingError {} trait Keyword {} impl Value { fn parse(value: &str, line_no: usize) -> Result { todo!(); } } ``` when formatted with `rustfmt --edition 2021 --emit stdout --config max_width=90,brace_style=AlwaysNextLine` becomes: ``` struct Value {} struct ParsingError {} trait Keyword {} impl Value { fn parse(value: &str, line_no: usize) -> Result { todo!(); } } ``` --- engine/Cargo.toml | 2 +- engine/src/renderer/main_render_pass.rs | 21 ++++++++++++--------- engine/src/shader.rs | 15 ++++++++------- engine/src/windowing/mouse.rs | 3 +-- 4 files changed, 22 insertions(+), 19 deletions(-) (limited to 'engine') diff --git a/engine/Cargo.toml b/engine/Cargo.toml index 9b91df8..6187bb4 100644 --- a/engine/Cargo.toml +++ b/engine/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "engine" version = "0.1.0" -edition = "2024" +edition = "2021" [dependencies] glutin = "0.32.3" diff --git a/engine/src/renderer/main_render_pass.rs b/engine/src/renderer/main_render_pass.rs index abd1022..04050f8 100644 --- a/engine/src/renderer/main_render_pass.rs +++ b/engine/src/renderer/main_render_pass.rs @@ -1,9 +1,8 @@ +use crate::asset::Assets; +use crate::draw_flags::{DrawFlags, NoDraw, PolygonModeConfig}; use crate::ecs::Query; use crate::ecs::query::term::{With, Without}; use crate::ecs::sole::Single; - -use crate::asset::Assets; -use crate::draw_flags::{DrawFlags, NoDraw, PolygonModeConfig}; use crate::model::{MaterialSearchResult, Model}; use crate::renderer::object::{Id as RendererObjectId, Store as RendererObjectStore}; use crate::renderer::{ @@ -192,9 +191,13 @@ pub fn add_main_render_passes( )); } - if let Some(draw_flags) = draw_flags.as_deref() - && draw_flags.polygon_mode_config != PolygonModeConfig::default() - { + if let Some(draw_flags) = draw_flags.as_deref().and_then(|draw_flags| { + if draw_flags.polygon_mode_config != PolygonModeConfig::default() { + Some(draw_flags) + } else { + None + } + }) { render_pass .commands .push(RendererCommand::UpdateDrawProperties( @@ -223,9 +226,9 @@ pub fn add_main_render_passes( RendererDrawMeshOptions::default(), )); - if let Some(draw_flags) = draw_flags.as_deref() - && draw_flags.polygon_mode_config != PolygonModeConfig::default() - { + if draw_flags.as_deref().is_some_and(|draw_flags| { + draw_flags.polygon_mode_config != PolygonModeConfig::default() + }) { render_pass .commands .push(RendererCommand::UpdateDrawProperties( diff --git a/engine/src/shader.rs b/engine/src/shader.rs index d5611ca..7988724 100644 --- a/engine/src/shader.rs +++ b/engine/src/shader.rs @@ -6,10 +6,6 @@ use std::path::Path; use std::str::Utf8Error; use bitflags::{bitflags, bitflags_match}; -use crate::ecs::pair::{ChildOf, Pair}; -use crate::ecs::phase::{POST_UPDATE as POST_UPDATE_PHASE, Phase, START as START_PHASE}; -use crate::ecs::sole::Single; -use crate::ecs::{Component, Sole, declare_entity}; use shader_slang::{ Blob as SlangBlob, ComponentType as SlangComponentType, @@ -32,6 +28,10 @@ use crate::asset::{ Submitter as AssetSubmitter, }; use crate::builder; +use crate::ecs::pair::{ChildOf, Pair}; +use crate::ecs::phase::{POST_UPDATE as POST_UPDATE_PHASE, Phase, START as START_PHASE}; +use crate::ecs::sole::Single; +use crate::ecs::{Component, Sole, declare_entity}; use crate::shader::default::{ ASSET_LABEL, enqueue_set_shader_bindings as default_shader_enqueue_set_shader_bindings, @@ -77,7 +77,7 @@ pub struct Module impl Module { - pub fn entry_points(&self) -> impl ExactSizeIterator + pub fn entry_points(&self) -> impl ExactSizeIterator + use<'_> { self.inner .entry_points() @@ -218,8 +218,9 @@ impl<'a> ProgramReflection<'a> }) } - pub fn entry_points(&self) - -> impl ExactSizeIterator> + pub fn entry_points( + &self, + ) -> impl ExactSizeIterator> + use<'a> { self.inner .entry_points() diff --git a/engine/src/windowing/mouse.rs b/engine/src/windowing/mouse.rs index 2a3324e..f4969ea 100644 --- a/engine/src/windowing/mouse.rs +++ b/engine/src/windowing/mouse.rs @@ -1,7 +1,6 @@ use std::collections::HashMap; use crate::ecs::Sole; - use crate::vector::Vec2; #[derive(Debug, Default, Clone, Sole)] @@ -48,7 +47,7 @@ impl Buttons /// Returns a iterator that yields buttons and their current states. Only buttons with /// states is included. - pub fn all_current(&self) -> impl Iterator + pub fn all_current(&self) -> impl Iterator + use<'_> { self.map .iter() -- cgit v1.2.3-18-g5258