Skip to content

Commit

Permalink
clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrav committed Mar 4, 2023
1 parent 67cbdd2 commit 7e829ec
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ jobs:

- name: Cargo Test
run: |
cargo test
cargo test --release
- name: Cargo Clippy
run: |
cargo clippy -- -W clippy::pedantic -W clippy::nursery -W clippy::unwrap_used
cargo clippy --release -- -W clippy::pedantic -W clippy::nursery -W clippy::unwrap_used
- name: Cargo Build Binary
run: |
cd rust
cargo build --release
chmod +x target/release/${{ github.event.repository.name }}
Expand Down
24 changes: 21 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,33 @@
},
"label": "rust: cargo build",
},
{
"type": "cargo",
"command": "clippy",
"problemMatcher": [
"$rustc"
],
"args": [
"--fix",
"--allow-dirty",
"--",
"-W",
"clippy::pedantic",
"-W",
"clippy::nursery",
"-W",
"clippy::unwrap_used",
],
"group": "build",
"label": "rust: cargo clippy fix",
},
{
"type": "cargo",
"command": "build",
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
},
"group": "build",
"args": [
"--release"
],
Expand Down
4 changes: 2 additions & 2 deletions src/phone_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ impl Options {
let combinations = Some(10 - prefix.to_string().len());
Self {
country_code: country_code.into(),
prefix: format!("{country_code}{prefix}").into(),
combinations: combinations.into(),
prefix: format!("{country_code}{prefix}"),
combinations,
file: file.into(),
}
}
Expand Down
17 changes: 7 additions & 10 deletions src/russian_roulette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Gun {
_ => println!("Barrel with size {} opened", &barrel_size),
}
let mut barrel = vec![false; barrel_size as usize];
let mut hammer_pos: usize = 0;
let mut hammer_pos: u8 = 0;
match bullets {
0 => panic!("0 Bullets!"),
_ => {
Expand All @@ -47,19 +47,16 @@ impl Gun {
} else {
println!("Barrel loading with {} bullets", &bullets);
while bullets > 0 {
hammer_pos = (c_rand_u8() % barrel_size) as usize;
if barrel[hammer_pos] == false {
barrel[hammer_pos] = true;
hammer_pos = c_rand_u8() % barrel_size;
if !barrel[hammer_pos as usize] {
barrel[hammer_pos as usize] = true;
bullets -= 1;
}
}
}
}
}
Self {
barrel: barrel,
hammer_pos: hammer_pos as u8,
}
Self { barrel, hammer_pos }
}

// Trigger gun an fire round if loaded in barrel
Expand All @@ -68,9 +65,9 @@ impl Gun {
let real_pos = self.hammer_pos as usize % self.barrel.len();
if self.barrel[real_pos] {
self.barrel[real_pos] = false;
println!("BAAANNG!!")
println!("BAAANNG!!");
} else {
println!("*Click*, {} empty", real_pos)
println!("*Click*, {real_pos} empty");
}
}
}
Expand Down

0 comments on commit 7e829ec

Please sign in to comment.