43
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:
...
27
votes
Accepted
Simplest way to write "FizzBuzz" in Rust
I think that match is better, you just do not know how to cook it ;)
...
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 ...
16
votes
Accepted
Binary Tree Implementation in Rust
Examples have first-class support in Cargo. Place them in a directory examples next to src. They can then be run with ...
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. ...
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 ...
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 ...
13
votes
Accepted
12
votes
Accepted
11
votes
Accepted
Insertion sort in Rust
As you have already been made aware, you should not be using &mut Vec<T> unless you plan on adding or removing items from the ...
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 ...
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 ...
10
votes
Accepted
Gamma function in Rust
There's not a lot of code here so there's not a lot to say. ^_^
Implementations like this are generally outside of the day-to-day knowledge of most programmers. You may wish to include a reference in ...
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:
...
10
votes
Accepted
BTreeMap as a multimap in Rust
Idiomatic Rust style is to place braces on same line. When the function definition gets longer than one line then the brace lives on the next line all on its own.
Learn and love the ...
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 ...
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 ...
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 ...
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 ...
9
votes
Accepted
Tokenize s-expressions in Rust
The biggest thing I can say is listen to your tests. The very first thing I noticed as I was skimming is how repetitive they were. Even worse, the repeated parts drowned out the interesting aspects of ...
9
votes
Accepted
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 ...
9
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 ...
8
votes
Selection sort algorithm in Rust
You could use min_by_key to find the minimum's index and the method swap defined in slices:
...
8
votes
Accepted
Calculating word-wise CRC
Overall, this looks very reasonable! There are some small style nits like spaces inside of struct declarations. A few bigger points:
The Rust community loves crates and reusing existing work. In this ...
8
votes
Accepted
Reversal of a singly-linked list in Rust
Before I begin, I recommend reading Learning Rust With Entirely Too Many Linked Lists.
Avoid unwraps, especially those after checking ...
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 ...
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 ...
8
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 ...
8
votes
Rust Torrent Parser
For deserialization, its a lost easier if you use serde. Then you can do something like this:
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
rust × 843beginner × 204
performance × 68
algorithm × 52
programming-challenge × 40
parsing × 35
strings × 28
multithreading × 22
primes × 21
iterator × 21
reinventing-the-wheel × 20
file × 16
error-handling × 15
sorting × 14
tree × 14
game × 13
linked-list × 13
file-system × 12
generics × 12
vectors × 12
sieve-of-eratosthenes × 12
console × 11
recursion × 10
comparative-review × 10
cryptography × 10