Skip to content

rustfmt source code and GitHub action #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/rustfmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: "Rustfmt check"

on:
push:
pull_request:

jobs:
# Check formatting with rustfmt
formatting:
name: rustfmt all repo
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
run: find . -type f -name "*.rs" | xargs rustfmt --check
1 change: 1 addition & 0 deletions examples/hello/src/lib/russian.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

7 changes: 2 additions & 5 deletions exercise/c_simple_types/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,20 @@ 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.
//
//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
// "Ding, you found 13!"
//
//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:
Expand Down Expand Up @@ -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()
);
}

9 changes: 4 additions & 5 deletions exercise/d_control_flow_strings/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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);
}

Expand All @@ -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) {
Expand All @@ -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.
}
9 changes: 4 additions & 5 deletions exercise/f_structs_traits/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
//
// 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).
//
// #[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);

Expand Down Expand Up @@ -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;
}
}
}
7 changes: 3 additions & 4 deletions exercise/g_collections_enums/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -74,4 +73,4 @@ fn get_arrow_coords(num: u32) -> Vec<Coord> {
coords.push(coord);
}
coords
}
}