From 8bbb6c3c7977dc81f3bc2f5596fbc103ba118052 Mon Sep 17 00:00:00 2001 From: cpmachado Date: Sun, 2 Mar 2025 01:12:13 +0000 Subject: [PATCH 1/4] rustfmt all source code --- examples/hello/src/lib/russian.rs | 1 + exercise/c_simple_types/src/main.rs | 7 ++----- exercise/d_control_flow_strings/src/main.rs | 9 ++++----- exercise/f_structs_traits/src/main.rs | 9 ++++----- exercise/g_collections_enums/src/main.rs | 7 +++---- 5 files changed, 14 insertions(+), 19 deletions(-) diff --git a/examples/hello/src/lib/russian.rs b/examples/hello/src/lib/russian.rs index e69de29b..8b137891 100644 --- a/examples/hello/src/lib/russian.rs +++ b/examples/hello/src/lib/russian.rs @@ -0,0 +1 @@ + diff --git a/exercise/c_simple_types/src/main.rs b/exercise/c_simple_types/src/main.rs index 0fdcb291..2e3f0114 100644 --- a/exercise/c_simple_types/src/main.rs +++ b/exercise/c_simple_types/src/main.rs @@ -11,7 +11,6 @@ fn main() { // //print_difference( ... ); // Uncomment and finish this line - // 2. We want to use the `print_array` function to print coords...but coords isn't an array! // Create an array of type [f32; 2] and initialize it to contain the // information from coords. Uncomment the print_array line and run the code. @@ -19,7 +18,6 @@ fn main() { //let coords_arr... // create an array literal out of parts of `coord` here //print_array(coords_arr); // and pass it in here (this line doesn't need to change) - let series = [1, 1, 2, 3, 5, 8, 13]; // 3. Make the `ding` function happy by passing it the value 13 out of the `series` array. // Use array indexing. Done correctly, `cargo run` will produce the additional output @@ -27,7 +25,6 @@ fn main() { // //ding(...); - let mess = ([3, 2], 3.14, [(false, -3), (true, -100)], 5, "candy"); // 4. Pass the `on_off` function the value `true` from the variable `mess`. Done correctly, // `cargo run` will produce the additional output "Lights are on!" I'll get you started: @@ -78,6 +75,6 @@ fn print_distance(z: (f32, f32)) { // body to use x and y. println!( "Distance to the origin is {}", - ( z.0.powf(2.0) + z.1.powf(2.0) ).sqrt()); + (z.0.powf(2.0) + z.1.powf(2.0)).sqrt() + ); } - diff --git a/exercise/d_control_flow_strings/src/main.rs b/exercise/d_control_flow_strings/src/main.rs index 416c4c4f..7def6a25 100644 --- a/exercise/d_control_flow_strings/src/main.rs +++ b/exercise/d_control_flow_strings/src/main.rs @@ -20,7 +20,6 @@ fn main() { // - If arg is "double", then call the double() function // - If arg is anything else, then call the count() function, passing "arg" to it. - // 1b. Now try passing "sum", "double" and "bananas" to the program by adding your argument // after "cargo run". For example "cargo run sum" } @@ -32,7 +31,6 @@ fn sum() { // and add them all together (increment the `sum` variable). Hint: You should get 255 // Run it with `cargo run sum` - println!("The sum is {}", sum); } @@ -43,8 +41,10 @@ fn double() { // by 2) until `x` is larger than 500. Increment `count` each time through the loop. Run it // with `cargo run double` Hint: The answer is 9 times. - - println!("You can double x {} times until x is larger than 500", count); + println!( + "You can double x {} times until x is larger than 500", + count + ); } fn count(arg: String) { @@ -53,6 +53,5 @@ fn count(arg: String) { // // print!("{} ", arg); // Execute this line 8 times, and then break. `print!` doesn't add a newline. - println!(); // This will output just a newline at the end for cleanliness. } diff --git a/exercise/f_structs_traits/src/main.rs b/exercise/f_structs_traits/src/main.rs index b87ffb66..baa58eac 100644 --- a/exercise/f_structs_traits/src/main.rs +++ b/exercise/f_structs_traits/src/main.rs @@ -6,7 +6,6 @@ // // trait Bite... - // 2. Now create a struct named Grapes with a field that tracks how many grapes are left. If you // need a hint, look at how it was done for Carrot at the bottom of this file (you should probably // use a different field, though). @@ -14,16 +13,16 @@ // #[derive(Debug)] // include this line right before your struct definition // struct Grapes... - // 3. Implement Bite for Grapes. When you bite a Grapes, subtract 1 from how many grapes are left. // If you need a hint, look at how it was done for Carrot at the bottom of this file. // // impl Bite for... - fn main() { // Once you finish #1 above, this part should work. - let mut carrot = Carrot { percent_left: 100.0 }; + let mut carrot = Carrot { + percent_left: 100.0, + }; carrot.bite(); println!("I take a bite: {:?}", carrot); @@ -55,4 +54,4 @@ impl Bite for Carrot { // Eat 20% of the remaining carrot. It may take awhile to eat it all... self.percent_left *= 0.8; } -} \ No newline at end of file +} diff --git a/exercise/g_collections_enums/src/main.rs b/exercise/g_collections_enums/src/main.rs index 72493293..fd10c0a6 100644 --- a/exercise/g_collections_enums/src/main.rs +++ b/exercise/g_collections_enums/src/main.rs @@ -35,7 +35,6 @@ fn main() { // - Between 1.0 and 5.0 -- `Shot::Hit(value)` // - Greater than 5.0 -- `Shot::Miss` - let mut total = 0; // 3. Finally, loop through each shot in shots and add its points to total @@ -58,9 +57,9 @@ impl Coord { "coord is {:.1} away, at ({:.1}, {:.1})", self.distance_from_center(), self.x, - self.y); + self.y + ); } - } // Generate some random coordinates @@ -74,4 +73,4 @@ fn get_arrow_coords(num: u32) -> Vec { coords.push(coord); } coords -} \ No newline at end of file +} From dd2bae9113757a0957fff9084076a4160d732c70 Mon Sep 17 00:00:00 2001 From: cpmachado Date: Sun, 2 Mar 2025 01:15:10 +0000 Subject: [PATCH 2/4] github action for rustfmt --- .github/workflows/rustfmt.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .github/workflows/rustfmt.yml diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml new file mode 100644 index 00000000..a3eb4d2a --- /dev/null +++ b/.github/workflows/rustfmt.yml @@ -0,0 +1,19 @@ +name: "Rustfmt check" + +on: + push: + pull_request: + +jobs: + # Check formatting with rustfmt + formatting: + name: cargo fmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + # Ensure rustfmt is installed and setup problem matcher + - uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + components: rustfmt + - name: Rustfmt Check + uses: actions-rust-lang/rustfmt@v1 From 571a740292de5f79710b4afb7c06a296fdadb0e6 Mon Sep 17 00:00:00 2001 From: cpmachado Date: Sun, 2 Mar 2025 01:23:12 +0000 Subject: [PATCH 3/4] Test correcting action --- .github/workflows/rustfmt.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml index a3eb4d2a..d7498897 100644 --- a/.github/workflows/rustfmt.yml +++ b/.github/workflows/rustfmt.yml @@ -16,4 +16,4 @@ jobs: with: components: rustfmt - name: Rustfmt Check - uses: actions-rust-lang/rustfmt@v1 + run: find . -type f -name "*.rs" | xargs rustfmt --check From 0a89da1523ebf35e6e13e175652d70c7a811e540 Mon Sep 17 00:00:00 2001 From: cpmachado Date: Sun, 2 Mar 2025 01:25:27 +0000 Subject: [PATCH 4/4] Rename stage to be more explicit --- .github/workflows/rustfmt.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rustfmt.yml b/.github/workflows/rustfmt.yml index d7498897..5f1021e4 100644 --- a/.github/workflows/rustfmt.yml +++ b/.github/workflows/rustfmt.yml @@ -7,7 +7,7 @@ on: jobs: # Check formatting with rustfmt formatting: - name: cargo fmt + name: rustfmt all repo runs-on: ubuntu-latest steps: - uses: actions/checkout@v4