Skip to main content
44 votes
Accepted

Calculate mean, median, and mode in Rust

Learn to love rustfmt. For example, the Rust standard is 4-space indents. Learn to love Clippy, which can show you the more idiomatic way to iterate over a collection: ...
Shepmaster's user avatar
  • 8,798
23 votes
Accepted

Web crawler in Rust

Cargo Fmt There's a very common tool accessible through cargo which can format all of the code in your project according to Rust's official style guide. Many major ...
Cedric Hutchings's user avatar
16 votes
Accepted

Shoe shine shop model in Rust

Correctness of the solution On reflection, I'm not sure either the C++ or the Rust code solves the problem as stated. I'm not completely sure I understand the shoe shine shop model so I may be wrong. ...
trent's user avatar
  • 1,134
15 votes
Accepted

Fahrenheit and Celsius converter in Rust

The first thing I always do is running clippy. You will catch some things that are not neccessary, e.g. fn main() -> () can ...
hellow's user avatar
  • 474
14 votes

Calculating the median and mode of a list of integers

Your Code Is Buggy. Test It! Try this testcase: assert_eq!(exercise_median_of_vector(&mut Vec::from([1])), 1); Always write test cases for your code! In a ...
Davislor's user avatar
  • 9,115
13 votes
Accepted

Writing slice compare in a more compact way

What about this: ...
ElleJay's user avatar
  • 919
12 votes
Accepted

Circular FIFO Buffer

Your code looks pretty decent. My two cents: Implement Default ...
hellow's user avatar
  • 474
12 votes

Builder pattern in Rust

Ownership Builder should return an instance, not a reference to it, and be consumed during build call. This is semantically correct: builder is a one-off logic ...
STerliakov's user avatar
  • 2,034
11 votes
Accepted

Pig Latin exercise in Rust

For overall issues, these jump out: s[i].is_alphabetic() && i < s.len() can panic, because you access the value before checking the length, it would have ...
loganfsmyth's user avatar
11 votes
Accepted

n-th Fibonacci number with memoization

I like this. Your code is clean and pretty readable. I recommend using rustfmt, if only because it will stop annoying people on the internet from recommending you ...
trent's user avatar
  • 1,134
10 votes

Rust Brainfuck interpreter

Profile You can only improve what you can measure. So first of all let us run callgrind to check where we spent most of our time: ...
Zeta's user avatar
  • 19.7k
10 votes
Accepted

Recursive Fibonacci in Rust with memoization

There's no reason to ascribe a type to memo. Don't expose the memoization logic outside the call. Instead, create a shim function that creates the memoization ...
Shepmaster's user avatar
  • 8,798
10 votes

Shoe shine shop model in Rust

Forgive me, I am unable to review the rust code because I do not know rust, I am only reviewing the c++ code.. Use System Defined Exit Codes Returning -1 as an ...
pacmaninbw's user avatar
  • 26.1k
10 votes
Accepted

Number-guessing game based on Rust tutorial

Welcome to Rust! Code Formatting There are some inconsistencies in your formatting — I have run cargo fmt to get rid of them. Naming There's no need to prefix ...
L. F.'s user avatar
  • 9,705
10 votes
Accepted

piglatin exercise in rust

Not a bad start. Some ways it could be improved: Use &str for String Slices Currently, you cannot call ...
Davislor's user avatar
  • 9,115
9 votes
Accepted

Check whether an integer's leftmost bits are ones in Rust

The problem is that have the feeling that there must be a much simple solution to this problem. You're right! Integers in Rust have many useful bitwise operations (as well as other useful ones like ...
trent's user avatar
  • 1,134
9 votes
Accepted

Rust: exercise of employees and names

To start, I have some general tips. Run your code through rustfmt to get consistent formatting and make code easier to read. Run your code through clippy to get tips on common mistakes (clippy had ...
JayDepp's user avatar
  • 541
9 votes

Rust Torrent Parser

For deserialization, its a lost easier if you use serde. Then you can do something like this: ...
Winston Ewert's user avatar
9 votes

Temperature Scale Converter in Rust

This looks like a pretty good first effort, but there are definitely some stylistic issues here as well as a few more advanced features that would make this a lot better. Getting started with the ...
Aiden4's user avatar
  • 286
9 votes
Accepted

Beginner Rust Todo app

Use cargo clippy to find common mistakes: Redundant trim In input.trim().split_whitespace() ...
Dornteufel's user avatar
8 votes
Accepted

MergeSort in Rust

Disclaimer: I'm also new to Rust, but I have a background in C, C++ and Haskell. Take everything I say with a grain of salt. All of that looks reasonable, except for the ...
Zeta's user avatar
  • 19.7k
8 votes
Accepted

Alphabet cypher in Rust

Disclaimer: I'm a Rust beginner with a background in C and C++. Now that I've lost my credibility, let's have a look at your code. Use rustfmt, clippy and rustc There are (at least) three helpful ...
Zeta's user avatar
  • 19.7k
8 votes
Accepted

Dijkstra's algorithm in Rust

Pay attention to compiler warnings. Rust is a statically-compiled language. One of the big reasons you choose such a language is to get information at compile time: ...
Shepmaster's user avatar
  • 8,798
8 votes

Writing slice compare in a more compact way

I take the idea to return an Ordering from the other answer: ...
Boiethios's user avatar
  • 600
8 votes
Accepted

Solution to the Rustlings from_into exercise

Congratulations on your Rustlings challenge. Your code seems fine and is easy to understand, however, as you said yourself, some parts of it don't seem idiomatic yet. However, before I begin this ...
Zeta's user avatar
  • 19.7k
8 votes

Idiomatic use of `Option` and `unwrap` in mean, median and mode Rust program for Chapter 8 of The Book

Good job in separating what you did into self-contained functions. Some comments on design and style: First things first: always run Clippy! (cargo clippy) Its ...
Caleb Stanford's user avatar
8 votes
Accepted

Rust Simple Stats Program

io::stdin().read_line(&mut num); Here you are ignoring the Result from read_line; you ...
Kevin Reid's user avatar
8 votes

Binary adder implemented in Rust

Because you're only working with ascii 0 and 1 you could use bytes instead of characters everywhere, it saves 3 bytes for every ...
cafce25's user avatar
  • 204
8 votes
Accepted

Merge Sorted Array in Rust

A lot of room for improvement here! :) For the i as usize issue, the general principle is: whenever if you have variables indexing into an array, make them ...
Caleb Stanford's user avatar
8 votes

Temperature unit conversion in Rust

Use cargo fmt or rustfmt to format your code. Then use clippy to lint it. Many IDEs allow ...
Richard Neumann's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible