Skip to content

Format Rust code using rustfmt #572

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

Merged
merged 1 commit into from
Jan 7, 2019
Merged
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
6 changes: 3 additions & 3 deletions contents/bogo_sort/code/rust/bogosort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ extern crate rand;

use rand::{thread_rng, Rng};

fn is_sorted(arr : &[i32]) -> bool {
fn is_sorted(arr: &[i32]) -> bool {
for i in 1..arr.len() {
if arr[i-1] > arr[i] {
if arr[i - 1] > arr[i] {
return false;
}
}
true
}

fn bogo_sort(arr : &mut [i32]) {
fn bogo_sort(arr: &mut [i32]) {
while !is_sorted(arr) {
thread_rng().shuffle(arr);
}
Expand Down
4 changes: 2 additions & 2 deletions contents/bubble_sort/code/rust/bubble_sort.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate rand; // External crate that provides random number generation tools

use rand::{thread_rng, Rng}; // Used for random number generation
use rand::distributions::Uniform; // Used for a uniform distribution
use rand::{thread_rng, Rng}; // Used for random number generation

fn bubble_sort(a: &mut [u32]) {
let n = a.len();
Expand All @@ -24,4 +24,4 @@ fn main() {
println!("Before sorting: {:?}", rand_vec);
bubble_sort(&mut rand_vec);
println!("After sorting: {:?}", rand_vec);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ fn main() {
println!("{}", chk1);
println!("{}", chk2);
}

5 changes: 4 additions & 1 deletion contents/monte_carlo_integration/code/rust/monte_carlo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ fn monte_carlo(n: i64) -> f64 {
fn main() {
let pi_estimate = monte_carlo(10000000);

println!("Percent error is {:.3}%", (100.0 * (pi_estimate - PI).abs() / PI));
println!(
"Percent error is {:.3}%",
(100.0 * (pi_estimate - PI).abs() / PI)
);
}
14 changes: 10 additions & 4 deletions contents/tree_traversal/code/rust/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn dfs_recursive_postorder(n: &Node) {
}

fn dfs_recursive_inorder_btree(n: &Node) {
if n.children.len() == 2{
if n.children.len() == 2 {
dfs_recursive_inorder_btree(&n.children[1]);
println!("{}", n.value);
dfs_recursive_inorder_btree(&n.children[0]);
Expand All @@ -46,7 +46,7 @@ fn dfs_stack(n: &Node) {
}
}

fn bfs_queue(n: &Node){
fn bfs_queue(n: &Node) {
let mut queue = VecDeque::new();
queue.push_back(n);

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

fn create_tree(num_row: u64, num_child: u64) -> Node {
if num_row == 0 {
return Node { children: vec![], value: 0 };
return Node {
children: vec![],
value: 0,
};
}

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

Node { children, value: num_row }
Node {
children,
value: num_row,
}
}

fn main() {
Expand Down
10 changes: 8 additions & 2 deletions contents/verlet_integration/code/rust/verlet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ fn main() {
let (time_vv, vel_vv) = velocity_verlet(5.0, -10.0, 0.01);

println!("Time for original Verlet integration: {}", time_v);
println!("Time and velocity for Stormer Verlet integration: {}, {}", time_sv, vel_sv);
println!("Time and velocity for velocity Verlet integration: {}, {}", time_vv, vel_vv);
println!(
"Time and velocity for Stormer Verlet integration: {}, {}",
time_sv, vel_sv
);
println!(
"Time and velocity for velocity Verlet integration: {}, {}",
time_vv, vel_vv
);
}