From 7611a3d634fc4b2003d94319b1e45ed7305ef911 Mon Sep 17 00:00:00 2001 From: Sameer Puri Date: Sun, 22 Feb 2026 12:27:15 -0800 Subject: [PATCH] Use nightly rustfmt with import sorting --- .github/workflows/cli.yml | 11 +++++++++-- .github/workflows/lib.yml | 11 +++++++++-- .github/workflows/web.yml | 11 +++++++++-- cli/src/main.rs | 16 ++++++++-------- lib/src/arc.rs | 4 ++-- lib/src/converter/mod.rs | 9 ++++++--- lib/src/converter/path.rs | 3 +-- lib/src/converter/units.rs | 6 ++---- lib/src/lib.rs | 3 ++- lib/src/turtle/g_code.rs | 9 +++++---- lib/src/turtle/mod.rs | 4 +--- rustfmt.toml | 3 +++ web/src/forms/inputs.rs | 3 ++- web/src/forms/mod.rs | 3 ++- web/src/state.rs | 3 ++- web/src/ui/mod.rs | 1 + web/src/util.rs | 3 ++- 17 files changed, 66 insertions(+), 37 deletions(-) create mode 100644 rustfmt.toml diff --git a/.github/workflows/cli.yml b/.github/workflows/cli.yml index 04e37b5..dba91b5 100644 --- a/.github/workflows/cli.yml +++ b/.github/workflows/cli.yml @@ -13,12 +13,19 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 + - name: Get stable release date + id: stable-date + run: echo "date=$(curl -s https://static.rust-lang.org/dist/channel-rust-stable.toml | grep '^date' -m1 | cut -d'"' -f2)" >> $GITHUB_OUTPUT - uses: Swatinem/rust-cache@v2 - uses: dtolnay/rust-toolchain@stable with: - components: rustfmt, clippy + toolchain: nightly-${{ steps.stable-date.outputs.date }} + components: rustfmt + - uses: dtolnay/rust-toolchain@stable + with: + components: clippy - name: Fmt - run: cargo fmt --check -p svg2gcode-cli + run: cargo +nightly-${{ steps.stable-date.outputs.date }} fmt --check -p svg2gcode-cli - name: Clippy run: cargo clippy -p svg2gcode-cli -- -D warnings - name: Build diff --git a/.github/workflows/lib.yml b/.github/workflows/lib.yml index e09da87..8772ef9 100644 --- a/.github/workflows/lib.yml +++ b/.github/workflows/lib.yml @@ -13,14 +13,21 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 + - name: Get stable release date + id: stable-date + run: echo "date=$(curl -s https://static.rust-lang.org/dist/channel-rust-stable.toml | grep '^date' -m1 | cut -d'"' -f2)" >> $GITHUB_OUTPUT - uses: dtolnay/rust-toolchain@stable with: - components: rustfmt, clippy + toolchain: nightly-${{ steps.stable-date.outputs.date }} + components: rustfmt + - uses: dtolnay/rust-toolchain@stable + with: + components: clippy - uses: Swatinem/rust-cache@v2 - name: Install dependencies run: sudo apt-get update && sudo apt-get install -y libcairo2-dev - name: Fmt - run: cargo fmt --check -p svg2gcode + run: cargo +nightly-${{ steps.stable-date.outputs.date }} fmt --check -p svg2gcode - name: Clippy run: cargo clippy -p svg2gcode -- -D warnings - name: Build diff --git a/.github/workflows/web.yml b/.github/workflows/web.yml index 162c960..078554d 100644 --- a/.github/workflows/web.yml +++ b/.github/workflows/web.yml @@ -11,13 +11,20 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 + - name: Get stable release date + id: stable-date + run: echo "date=$(curl -s https://static.rust-lang.org/dist/channel-rust-stable.toml | grep '^date' -m1 | cut -d'"' -f2)" >> $GITHUB_OUTPUT - uses: Swatinem/rust-cache@v2 + - uses: dtolnay/rust-toolchain@stable + with: + toolchain: nightly-${{ steps.stable-date.outputs.date }} + components: rustfmt - uses: dtolnay/rust-toolchain@stable with: targets: wasm32-unknown-unknown - components: rustfmt, clippy + components: clippy - name: Fmt - run: cargo fmt --check -p svg2gcode-web + run: cargo +nightly-${{ steps.stable-date.outputs.date }} fmt --check -p svg2gcode-web - name: Clippy run: cargo clippy -p svg2gcode-web --target wasm32-unknown-unknown -- -D warnings - name: Check diff --git a/cli/src/main.rs b/cli/src/main.rs index 4601571..3899bd7 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,21 +1,21 @@ -use clap::Parser; -use g_code::{ - emit::{FormatOptions, format_gcode_io}, - parse::snippet_parser, -}; -use log::{error, info}; -use roxmltree::ParsingOptions; use std::{ env, fs::File, io::{self, Read, Write}, path::PathBuf, }; -use svgtypes::LengthListParser; +use clap::Parser; +use g_code::{ + emit::{FormatOptions, format_gcode_io}, + parse::snippet_parser, +}; +use log::{error, info}; +use roxmltree::ParsingOptions; use svg2gcode::{ ConversionOptions, Machine, Settings, SupportedFunctionality, Version, svg2program, }; +use svgtypes::LengthListParser; #[derive(Debug, Parser)] #[command(name = "svg2gcode", version, author, about)] diff --git a/lib/src/arc.rs b/lib/src/arc.rs index 05ac506..463c18a 100644 --- a/lib/src/arc.rs +++ b/lib/src/arc.rs @@ -90,7 +90,6 @@ where /// There are some slight deviations like using monotonic ranges instead of bounding by inflection points. /// /// Kaewsaiha, P., & Dejdumrong, N. (2012). Modeling of Bézier Curves Using a Combination of Linear and Circular Arc Approximations. 2012 Ninth International Conference on Computer Graphics, Imaging and Visualization. doi:10.1109/cgiv.2012.20 - /// fn flattened(&self, tolerance: S) -> Vec> { if (self.to - self.from).square_length() < S::EPSILON { return vec![]; @@ -277,9 +276,10 @@ impl Transformed for SvgArc { #[cfg(test)] mod tests { + use std::path::PathBuf; + use cairo::{Context, SvgSurface}; use lyon_geom::{CubicBezierSegment, Point, Vector, point, vector}; - use std::path::PathBuf; use svgtypes::PathParser; use crate::arc::{ArcOrLineSegment, FlattenWithArcs}; diff --git a/lib/src/converter/mod.rs b/lib/src/converter/mod.rs index e48f97b..c52ae34 100644 --- a/lib/src/converter/mod.rs +++ b/lib/src/converter/mod.rs @@ -6,8 +6,10 @@ use roxmltree::{Document, Node}; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; use svgtypes::Length; -use uom::si::f64::Length as UomLength; -use uom::si::length::{inch, millimeter}; +use uom::si::{ + f64::Length as UomLength, + length::{inch, millimeter}, +}; use self::units::CSS_DEFAULT_DPI; use crate::{Machine, turtle::*}; @@ -194,9 +196,10 @@ fn node_name(node: &Node, attr_to_print: &Option) -> String { #[cfg(all(test, feature = "serde"))] mod test { - use super::*; use svgtypes::LengthUnit; + use super::*; + #[test] fn serde_conversion_options_is_correct() { let default_struct = ConversionOptions::default(); diff --git a/lib/src/converter/path.rs b/lib/src/converter/path.rs index d7f0349..40c7f01 100644 --- a/lib/src/converter/path.rs +++ b/lib/src/converter/path.rs @@ -3,9 +3,8 @@ use log::debug; use lyon_geom::{ArcFlags, point, vector}; use svgtypes::PathSegment; -use crate::Turtle; - use super::Terrarium; +use crate::Turtle; /// Maps [`PathSegment`]s into concrete operations on the [`Terrarium`] /// diff --git a/lib/src/converter/units.rs b/lib/src/converter/units.rs index 0fbafca..efaa845 100644 --- a/lib/src/converter/units.rs +++ b/lib/src/converter/units.rs @@ -2,9 +2,8 @@ use log::warn; use roxmltree::Node; use svgtypes::{Length, LengthListParser}; -use crate::Turtle; - use super::ConversionVisitor; +use crate::Turtle; /// The DPI assumed by CSS is 96. /// @@ -49,8 +48,7 @@ impl<'a, T: Turtle> ConversionVisitor<'a, T> { /// A default DPI of 96 is used as per [CSS 4 §7.4](https://www.w3.org/TR/css-values/#resolution) pub fn length_to_user_units(&self, l: Length, hint: DimensionHint) -> f64 { use svgtypes::LengthUnit::*; - use uom::si::f64::Length; - use uom::si::length::*; + use uom::si::{f64::Length, length::*}; match l.unit { Cm => Length::new::(l.number).get::() * CSS_DEFAULT_DPI, diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 0003c59..5a49691 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -96,12 +96,13 @@ impl Default for Version { #[cfg(test)] mod test { - use super::*; use g_code::emit::{FormatOptions, Token}; use pretty_assertions::assert_eq; use roxmltree::ParsingOptions; use svgtypes::{Length, LengthUnit}; + use super::*; + /// The values change between debug and release builds for circular interpolation, /// so only check within a rough tolerance const TOLERANCE: f64 = 1E-10; diff --git a/lib/src/turtle/g_code.rs b/lib/src/turtle/g_code.rs index a0f44d9..36959de 100644 --- a/lib/src/turtle/g_code.rs +++ b/lib/src/turtle/g_code.rs @@ -1,12 +1,13 @@ -use std::borrow::Cow; -use std::fmt::Debug; +use std::{borrow::Cow, fmt::Debug}; use ::g_code::{command, emit::Token}; use lyon_geom::{CubicBezierSegment, Point, QuadraticBezierSegment, SvgArc}; use super::Turtle; -use crate::arc::{ArcOrLineSegment, FlattenWithArcs}; -use crate::machine::Machine; +use crate::{ + arc::{ArcOrLineSegment, FlattenWithArcs}, + machine::Machine, +}; /// Maps path segments into g-code operations #[derive(Debug)] diff --git a/lib/src/turtle/mod.rs b/lib/src/turtle/mod.rs index bd4d0a1..79a3155 100644 --- a/lib/src/turtle/mod.rs +++ b/lib/src/turtle/mod.rs @@ -11,9 +11,7 @@ use crate::arc::Transformed; mod dpi; mod g_code; mod preprocess; -pub use self::dpi::DpiConvertingTurtle; -pub use self::g_code::GCodeTurtle; -pub use self::preprocess::PreprocessTurtle; +pub use self::{dpi::DpiConvertingTurtle, g_code::GCodeTurtle, preprocess::PreprocessTurtle}; /// Abstraction for drawing paths based on [Turtle graphics](https://en.wikipedia.org/wiki/Turtle_graphics) pub trait Turtle: Debug { diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..e5a4dc4 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,3 @@ +imports_granularity = "Crate" +group_imports = "StdExternalCrate" +format_code_in_doc_comments = true diff --git a/web/src/forms/inputs.rs b/web/src/forms/inputs.rs index 02007e2..eca4a6f 100644 --- a/web/src/forms/inputs.rs +++ b/web/src/forms/inputs.rs @@ -1,5 +1,6 @@ -use paste::paste; use std::num::ParseFloatError; + +use paste::paste; use yew::prelude::*; use yewdux::functional::{use_store, use_store_value}; diff --git a/web/src/forms/mod.rs b/web/src/forms/mod.rs index 2f9b88c..2253153 100644 --- a/web/src/forms/mod.rs +++ b/web/src/forms/mod.rs @@ -1,10 +1,11 @@ +use std::{convert::TryInto, path::Path}; + use gloo_file::{ callbacks::{FileReader, read_as_bytes}, futures::read_as_text, }; use js_sys::TypeError; use roxmltree::{Document, ParsingOptions}; -use std::{convert::TryInto, path::Path}; use svg2gcode::{Settings, Version}; use wasm_bindgen::JsCast; use wasm_bindgen_futures::JsFuture; diff --git a/web/src/state.rs b/web/src/state.rs index e9c589e..2dd5747 100644 --- a/web/src/state.rs +++ b/web/src/state.rs @@ -1,5 +1,6 @@ -use serde::{Deserialize, Serialize}; use std::{convert::TryInto, num::ParseFloatError}; + +use serde::{Deserialize, Serialize}; use svg2gcode::{ ConversionConfig, MachineConfig, PostprocessConfig, Settings, SupportedFunctionality, Version, }; diff --git a/web/src/ui/mod.rs b/web/src/ui/mod.rs index 3f34f34..2ab0ab9 100644 --- a/web/src/ui/mod.rs +++ b/web/src/ui/mod.rs @@ -1,4 +1,5 @@ use std::fmt::Display; + use web_sys::{Event, FileList, HtmlInputElement, InputEvent, InputEventInit, MouseEvent}; use yew::{ AttrValue, Callback, Children, Html, NodeRef, Properties, TargetCast, ToHtml, classes, diff --git a/web/src/util.rs b/web/src/util.rs index 8313c2d..9f1c01c 100644 --- a/web/src/util.rs +++ b/web/src/util.rs @@ -1,5 +1,6 @@ -use base64::Engine; use std::path::Path; + +use base64::Engine; use wasm_bindgen::JsCast; use web_sys::{HtmlElement, window};