From 9860468df2bef97c43d01d7f657d6e219bfe4ed7 Mon Sep 17 00:00:00 2001 From: JieningYu Date: Mon, 11 Mar 2024 11:48:06 +0800 Subject: [PATCH] fmt --- crates/client/input/src/cursor_movement.rs | 14 ++-- crates/client/input/src/keyboard_input.rs | 68 ++++++++++--------- crates/client/input/src/lib.rs | 4 +- .../option/src/enums/cloud_render_mode.rs | 32 +++++---- crates/client/option/src/enums/mod.rs | 7 +- crates/client/option/src/enums/perspective.rs | 58 ++++++++-------- crates/client/option/src/tooltip_factory.rs | 4 +- crates/flare3d/example/src/main.rs | 2 +- crates/flare3d/src/state/camera.rs | 5 +- crates/flare3d/src/state/instance.rs | 2 +- crates/flare3d/src/state/mod.rs | 6 +- crates/flare3d/src/state/vertex.rs | 2 +- crates/flare3d/src/window.rs | 10 +-- crates/util/identifier/src/lib.rs | 8 +-- crates/util/identifier/src/tests.rs | 3 +- 15 files changed, 117 insertions(+), 108 deletions(-) diff --git a/crates/client/input/src/cursor_movement.rs b/crates/client/input/src/cursor_movement.rs index 4558395d..de22996f 100644 --- a/crates/client/input/src/cursor_movement.rs +++ b/crates/client/input/src/cursor_movement.rs @@ -1,10 +1,10 @@ /// Represents the movement of a cursor. #[derive(Debug)] pub enum CursorMovement { - /// Represents an absolute cursor movement. - Absolute, - /// Represents a relative cursor movement. - Relative, - /// Represents the end of cursor movement. - End, -} \ No newline at end of file + /// Represents an absolute cursor movement. + Absolute, + /// Represents a relative cursor movement. + Relative, + /// Represents the end of cursor movement. + End, +} diff --git a/crates/client/input/src/keyboard_input.rs b/crates/client/input/src/keyboard_input.rs index e2b33247..59f14862 100644 --- a/crates/client/input/src/keyboard_input.rs +++ b/crates/client/input/src/keyboard_input.rs @@ -5,46 +5,48 @@ use super::{Input, SlowDown}; pub struct KeyboardInput; impl KeyboardInput { - /// Creates a new instance of `KeyboardInput`. - pub fn new_input() -> Input { - Input::new(Self {}) - } + /// Creates a new instance of `KeyboardInput`. + pub fn new_input() -> Input { + Input::new(Self {}) + } } impl Input { - /// Returns the movement modifier based on the positive and negative flags. - pub fn get_movement_modifier(positive: bool, negative: bool) -> f32 { - if positive == negative { - 0.0 - } else { - if positive { - 1.0 - } else { - -1.0 - } - } - } + /// Returns the movement modifier based on the positive and negative flags. + pub fn get_movement_modifier(positive: bool, negative: bool) -> f32 { + if positive == negative { + 0.0 + } else { + if positive { + 1.0 + } else { + -1.0 + } + } + } } impl Input { - fn tick(&mut self, slow_down: SlowDown) { - self.pressing_forward = false; - self.pressing_backward = false; - self.pressing_left = false; - self.pressing_right = false; + fn tick(&mut self, slow_down: SlowDown) { + self.pressing_forward = false; + self.pressing_backward = false; + self.pressing_left = false; + self.pressing_right = false; - self.movement_forward = Self::get_movement_modifier(self.pressing_forward, self.pressing_backward); - self.movement_sideways = Self::get_movement_modifier(self.pressing_left, self.pressing_right); + self.movement_forward = + Self::get_movement_modifier(self.pressing_forward, self.pressing_backward); + self.movement_sideways = + Self::get_movement_modifier(self.pressing_left, self.pressing_right); - self.jumping = false; - self.sneaking = false; + self.jumping = false; + self.sneaking = false; - match slow_down { - SlowDown::Yes(factor) => { - self.movement_forward *= factor; - self.movement_sideways *= factor; - } - SlowDown::No => (), - } - } + match slow_down { + SlowDown::Yes(factor) => { + self.movement_forward *= factor; + self.movement_sideways *= factor; + } + SlowDown::No => (), + } + } } diff --git a/crates/client/input/src/lib.rs b/crates/client/input/src/lib.rs index f5c58b6c..f7c18d50 100644 --- a/crates/client/input/src/lib.rs +++ b/crates/client/input/src/lib.rs @@ -46,9 +46,7 @@ pub enum SlowDown { } impl SlowDownTickable for Input { - fn tick(&mut self, _slow_down: SlowDown) { - - } + fn tick(&mut self, _slow_down: SlowDown) {} } impl Input { diff --git a/crates/client/option/src/enums/cloud_render_mode.rs b/crates/client/option/src/enums/cloud_render_mode.rs index 18535b5b..a053ebcb 100644 --- a/crates/client/option/src/enums/cloud_render_mode.rs +++ b/crates/client/option/src/enums/cloud_render_mode.rs @@ -13,22 +13,26 @@ use super::ByUSizeId; /// This type represents `net.minecraft.client.option.CloudRenderMode` (yarn). #[derive(Debug, Sequence)] pub enum CloudRenderMode { - /// Doesn't render clouds. - Off, - /// Render clouds faster. - Fast, - /// Render clouds fancier. - Fancy + /// Doesn't render clouds. + Off, + /// Render clouds faster. + Fast, + /// Render clouds fancier. + Fancy, } impl ByUSizeId for CloudRenderMode {} impl Display for CloudRenderMode { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", match self { - CloudRenderMode::Off => "off", - CloudRenderMode::Fast => "fast", - CloudRenderMode::Fancy => "fancy", - }) - } -} \ No newline at end of file + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + match self { + CloudRenderMode::Off => "off", + CloudRenderMode::Fast => "fast", + CloudRenderMode::Fancy => "fancy", + } + ) + } +} diff --git a/crates/client/option/src/enums/mod.rs b/crates/client/option/src/enums/mod.rs index bf4f8e1a..aee2f053 100644 --- a/crates/client/option/src/enums/mod.rs +++ b/crates/client/option/src/enums/mod.rs @@ -9,8 +9,11 @@ pub mod perspective; /// If a [`Sequence`], often enums, implements this, it will be allowed to get items directly through [`usize`] indexes. Wrapping behavior is configurable. pub trait ByUSizeId: Sequence { - /// Gets the [`usize`] id. - fn get_usize_id(&self) -> Option where Self: PartialEq { + /// Gets the [`usize`] id. + fn get_usize_id(&self) -> Option + where + Self: PartialEq, + { let all = enum_iterator::all::().collect::>(); all.iter().position(|value| value == self) } diff --git a/crates/client/option/src/enums/perspective.rs b/crates/client/option/src/enums/perspective.rs index 6bd37d3c..2ff9d6cf 100644 --- a/crates/client/option/src/enums/perspective.rs +++ b/crates/client/option/src/enums/perspective.rs @@ -13,38 +13,42 @@ use super::ByUSizeId; /// This type represents `net.minecraft.client.option.Perspective` (yarn). #[derive(Debug, Sequence, PartialEq)] pub enum Perspective { - /// 1st person perspective. - FirstPerson, - /// 3rd person perspective, camera behind player. - ThirdPersonBack, - /// 3rd person perspective, camera in front of player. - ThirdPersonFront + /// 1st person perspective. + FirstPerson, + /// 3rd person perspective, camera behind player. + ThirdPersonBack, + /// 3rd person perspective, camera in front of player. + ThirdPersonFront, } impl ByUSizeId for Perspective {} impl Display for Perspective { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", match self { - Perspective::FirstPerson => "first_person", - Perspective::ThirdPersonBack => "third_person_back", - Perspective::ThirdPersonFront => "third_person_front", - }) - } + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + match self { + Perspective::FirstPerson => "first_person", + Perspective::ThirdPersonBack => "third_person_back", + Perspective::ThirdPersonFront => "third_person_front", + } + ) + } } impl Perspective { - pub fn is_first_person(&self) -> bool { - match self { - Perspective::FirstPerson => true, - _ => false - } - } - - pub fn is_front_view(&self) -> bool { - match self { - Perspective::ThirdPersonBack => false, - _ => true - } - } -} \ No newline at end of file + pub fn is_first_person(&self) -> bool { + match self { + Perspective::FirstPerson => true, + _ => false, + } + } + + pub fn is_front_view(&self) -> bool { + match self { + Perspective::ThirdPersonBack => false, + _ => true, + } + } +} diff --git a/crates/client/option/src/tooltip_factory.rs b/crates/client/option/src/tooltip_factory.rs index 12676558..bb1ab33c 100644 --- a/crates/client/option/src/tooltip_factory.rs +++ b/crates/client/option/src/tooltip_factory.rs @@ -1,3 +1,3 @@ pub trait TooltipFactory { - fn apply(&self, value: T) -> Option<()>; // Option -} \ No newline at end of file + fn apply(&self, value: T) -> Option<()>; // Option +} diff --git a/crates/flare3d/example/src/main.rs b/crates/flare3d/example/src/main.rs index d4d527cc..ca7a1ab1 100644 --- a/crates/flare3d/example/src/main.rs +++ b/crates/flare3d/example/src/main.rs @@ -2,5 +2,5 @@ use flare3d::window::Window; #[allow(unused_variables)] fn main() { - let window = Window::new(); + let window = Window::new(); } diff --git a/crates/flare3d/src/state/camera.rs b/crates/flare3d/src/state/camera.rs index 2985f70a..887e53a6 100644 --- a/crates/flare3d/src/state/camera.rs +++ b/crates/flare3d/src/state/camera.rs @@ -1,5 +1,8 @@ use glam::{Mat4, Quat, Vec3}; -use winit::{event::{ElementState, KeyEvent, WindowEvent}, keyboard::{KeyCode, PhysicalKey}}; +use winit::{ + event::{ElementState, KeyEvent, WindowEvent}, + keyboard::{KeyCode, PhysicalKey}, +}; pub struct Camera { pub eye: Vec3, diff --git a/crates/flare3d/src/state/instance.rs b/crates/flare3d/src/state/instance.rs index b65f7989..b494ee83 100644 --- a/crates/flare3d/src/state/instance.rs +++ b/crates/flare3d/src/state/instance.rs @@ -50,4 +50,4 @@ impl InstanceRaw { ], } } -} \ No newline at end of file +} diff --git a/crates/flare3d/src/state/mod.rs b/crates/flare3d/src/state/mod.rs index 128460d1..af9eca78 100644 --- a/crates/flare3d/src/state/mod.rs +++ b/crates/flare3d/src/state/mod.rs @@ -46,7 +46,7 @@ const INSTANCE_DISPLACEMENT: Vec3 = Vec3::new( ); pub struct State<'s> { - pub window: Arc, + pub window: Arc, pub size: winit::dpi::PhysicalSize, surface: wgpu::Surface<'s>, @@ -70,7 +70,7 @@ pub struct State<'s> { impl<'s> State<'s> { pub async fn new(event_loop: &EventLoop<()>) -> State<'s> { - let window = Arc::new(Window::new(event_loop).unwrap()); + let window = Arc::new(Window::new(event_loop).unwrap()); let size = window.inner_size(); let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { @@ -285,7 +285,7 @@ impl<'s> State<'s> { }); Self { - window, + window, size, surface, device, diff --git a/crates/flare3d/src/state/vertex.rs b/crates/flare3d/src/state/vertex.rs index 04b013be..d4546bd2 100644 --- a/crates/flare3d/src/state/vertex.rs +++ b/crates/flare3d/src/state/vertex.rs @@ -24,4 +24,4 @@ impl Vertex { ], } } -} \ No newline at end of file +} diff --git a/crates/flare3d/src/window.rs b/crates/flare3d/src/window.rs index 8b87fd04..6e0d6e08 100644 --- a/crates/flare3d/src/window.rs +++ b/crates/flare3d/src/window.rs @@ -13,7 +13,7 @@ pub struct Window<'w> { impl<'w> Window<'w> { pub fn new() -> Window<'w> { let event_loop = EventLoop::new().unwrap(); - let mut state = futures_executor::block_on(State::new(&event_loop)); + let mut state = futures_executor::block_on(State::new(&event_loop)); #[cfg(target_os = "macos")] let (_dl, semaphore) = { @@ -52,9 +52,7 @@ impl<'w> Window<'w> { state.update(); match state.render() { Ok(_) => {} - Err(wgpu::SurfaceError::Lost) => { - state.resize(state.size) - } + Err(wgpu::SurfaceError::Lost) => state.resize(state.size), Err(wgpu::SurfaceError::OutOfMemory) => target.exit(), Err(e) => eprintln!("{:?}", e), } @@ -84,8 +82,6 @@ impl<'w> Window<'w> { }) .unwrap(); - Self { - state - } + Self { state } } } diff --git a/crates/util/identifier/src/lib.rs b/crates/util/identifier/src/lib.rs index 81a2058f..e4a61064 100644 --- a/crates/util/identifier/src/lib.rs +++ b/crates/util/identifier/src/lib.rs @@ -17,10 +17,10 @@ pub struct Identifier { /// A generics wrapper for [`Identifier`]. /// The associated types [`Identifiers::N`] and [`Identifiers::P`] should be applied to [`Identifier`] when used. pub trait Identifiers { - /// Generic `N` that should be applied to [`Identifier`]. - type N; - /// Generic `P` that should be applied to [`Identifier`]. - type P; + /// Generic `N` that should be applied to [`Identifier`]. + type N; + /// Generic `P` that should be applied to [`Identifier`]. + type P; } impl Identifier { diff --git a/crates/util/identifier/src/tests.rs b/crates/util/identifier/src/tests.rs index 462f5667..1bd8c6ab 100644 --- a/crates/util/identifier/src/tests.rs +++ b/crates/util/identifier/src/tests.rs @@ -12,7 +12,6 @@ fn create_identifiers() { let identifier = Identifier::new(Namespace::new("n"), path); assert_eq!("n:a_b/42", identifier.to_string()); - let identifier = - format_identifier!("namespace".parse().unwrap() => "a", "b"; "c"; "42"); + let identifier = format_identifier!("namespace".parse().unwrap() => "a", "b"; "c"; "42"); assert_eq!("namespace:a_b/c/42", identifier.to_string()); }