From a5bf3ba18c8c3286a3bdf99ba72317a46fc34bef Mon Sep 17 00:00:00 2001 From: Martin Robinson Date: Thu, 1 Feb 2024 15:23:00 +0100 Subject: [PATCH] Make improvements to the CI (#54) - Switch the default branch to "main" - Run `cargo fmt --check` during CI - Format the source code - Improve job names --- .github/workflows/main.yml | 10 +++++----- src/app_unit.rs | 16 +++++++++------- src/lib.rs | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6857efe..06af3b5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -2,7 +2,7 @@ name: CI on: push: - branches: [master] + branches: [main] pull_request: merge_group: types: [checks_requested] @@ -17,13 +17,13 @@ jobs: toolchain: stable override: true profile: minimal + - name: Check Formatting + run: cargo fmt --check - name: Test run: cargo test - - - name: Serde check + - name: Check (`--features="serde_serialization"`) run: cargo check --features="serde_serialization" - - - name: Num traits check + - name: Check (`--features="num_traits"`) run: cargo check --features="num_traits" build_result: diff --git a/src/app_unit.rs b/src/app_unit.rs index 5fa9770..ac43ecf 100644 --- a/src/app_unit.rs +++ b/src/app_unit.rs @@ -5,21 +5,24 @@ #[cfg(feature = "num_traits")] use num_traits::Zero; #[cfg(feature = "serde_serialization")] -use serde::{Serialize, Deserialize, Deserializer}; +use serde::{Deserialize, Deserializer, Serialize}; -use std::{fmt, i32, default::Default, ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, Sub, SubAssign}}; use std::iter::Sum; +use std::{ + default::Default, + fmt, i32, + ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, Sub, SubAssign}, +}; /// The number of app units in a pixel. pub const AU_PER_PX: i32 = 60; /// The minimum number of app units, same as in Gecko. -pub const MIN_AU: Au = Au(- ((1 << 30) - 1)); +pub const MIN_AU: Au = Au(-((1 << 30) - 1)); /// The maximum number of app units, same as in Gecko. -/// +/// /// (1 << 30) - 1 lets us add/subtract two Au and check for overflow after the operation. pub const MAX_AU: Au = Au((1 << 30) - 1); - #[repr(transparent)] #[derive(Clone, Copy, Hash, PartialEq, PartialOrd, Eq, Ord, Default)] #[cfg_attr(feature = "serde_serialization", derive(Serialize), serde(transparent))] @@ -73,7 +76,6 @@ impl Sub for Au { fn sub(self, other: Au) -> Au { Au(self.0 - other.0).clamp() } - } impl Mul for i32 { @@ -391,7 +393,7 @@ fn convert() { assert_eq!(Au::from_f64_px(6.13), Au(368)); } -#[cfg(feature ="serde_serialization")] +#[cfg(feature = "serde_serialization")] #[test] fn serialize() { let serialized = ron::to_string(&Au(42)).unwrap(); diff --git a/src/lib.rs b/src/lib.rs index eb8cc8b..3e07ae6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,4 +8,4 @@ mod app_unit; -pub use app_unit::{Au, MIN_AU, MAX_AU, AU_PER_PX}; +pub use app_unit::{Au, AU_PER_PX, MAX_AU, MIN_AU};