Skip to content

Commit 6d718f7

Browse files
authored
Merge pull request #572 from barskern/chore/format-rust
Format Rust code using rustfmt
2 parents 3c38b6f + f42c2cf commit 6d718f7

File tree

6 files changed

+27
-13
lines changed

6 files changed

+27
-13
lines changed

contents/bogo_sort/code/rust/bogosort.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ extern crate rand;
44

55
use rand::{thread_rng, Rng};
66

7-
fn is_sorted(arr : &[i32]) -> bool {
7+
fn is_sorted(arr: &[i32]) -> bool {
88
for i in 1..arr.len() {
9-
if arr[i-1] > arr[i] {
9+
if arr[i - 1] > arr[i] {
1010
return false;
1111
}
1212
}
1313
true
1414
}
1515

16-
fn bogo_sort(arr : &mut [i32]) {
16+
fn bogo_sort(arr: &mut [i32]) {
1717
while !is_sorted(arr) {
1818
thread_rng().shuffle(arr);
1919
}

contents/bubble_sort/code/rust/bubble_sort.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate rand; // External crate that provides random number generation tools
22

3-
use rand::{thread_rng, Rng}; // Used for random number generation
43
use rand::distributions::Uniform; // Used for a uniform distribution
4+
use rand::{thread_rng, Rng}; // Used for random number generation
55

66
fn bubble_sort(a: &mut [u32]) {
77
let n = a.len();
@@ -24,4 +24,4 @@ fn main() {
2424
println!("Before sorting: {:?}", rand_vec);
2525
bubble_sort(&mut rand_vec);
2626
println!("After sorting: {:?}", rand_vec);
27-
}
27+
}

contents/euclidean_algorithm/code/rust/euclidean_example.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,3 @@ fn main() {
3232
println!("{}", chk1);
3333
println!("{}", chk2);
3434
}
35-

contents/monte_carlo_integration/code/rust/monte_carlo.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@ fn monte_carlo(n: i64) -> f64 {
2626
fn main() {
2727
let pi_estimate = monte_carlo(10000000);
2828

29-
println!("Percent error is {:.3}%", (100.0 * (pi_estimate - PI).abs() / PI));
29+
println!(
30+
"Percent error is {:.3}%",
31+
(100.0 * (pi_estimate - PI).abs() / PI)
32+
);
3033
}

contents/tree_traversal/code/rust/tree.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn dfs_recursive_postorder(n: &Node) {
2323
}
2424

2525
fn dfs_recursive_inorder_btree(n: &Node) {
26-
if n.children.len() == 2{
26+
if n.children.len() == 2 {
2727
dfs_recursive_inorder_btree(&n.children[1]);
2828
println!("{}", n.value);
2929
dfs_recursive_inorder_btree(&n.children[0]);
@@ -46,7 +46,7 @@ fn dfs_stack(n: &Node) {
4646
}
4747
}
4848

49-
fn bfs_queue(n: &Node){
49+
fn bfs_queue(n: &Node) {
5050
let mut queue = VecDeque::new();
5151
queue.push_back(n);
5252

@@ -58,14 +58,20 @@ fn bfs_queue(n: &Node){
5858

5959
fn create_tree(num_row: u64, num_child: u64) -> Node {
6060
if num_row == 0 {
61-
return Node { children: vec![], value: 0 };
61+
return Node {
62+
children: vec![],
63+
value: 0,
64+
};
6265
}
6366

6467
let children = (0..num_child)
6568
.map(|_| create_tree(num_row - 1, num_child))
6669
.collect();
6770

68-
Node { children, value: num_row }
71+
Node {
72+
children,
73+
value: num_row,
74+
}
6975
}
7076

7177
fn main() {

contents/verlet_integration/code/rust/verlet.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ fn main() {
5050
let (time_vv, vel_vv) = velocity_verlet(5.0, -10.0, 0.01);
5151

5252
println!("Time for original Verlet integration: {}", time_v);
53-
println!("Time and velocity for Stormer Verlet integration: {}, {}", time_sv, vel_sv);
54-
println!("Time and velocity for velocity Verlet integration: {}, {}", time_vv, vel_vv);
53+
println!(
54+
"Time and velocity for Stormer Verlet integration: {}, {}",
55+
time_sv, vel_sv
56+
);
57+
println!(
58+
"Time and velocity for velocity Verlet integration: {}, {}",
59+
time_vv, vel_vv
60+
);
5561
}

0 commit comments

Comments
 (0)