Data structures and Algorithms in Rust

Data structures and Algorithms in Rust
This tutorial is for developers or students who want to revisit basic data structures and algorithm design techniques and their solutions using Rust. Explore techniques for writing algorithm in Rust. The tutorial does not delve into any theoretical analyses and instead focuses on practical solutions.

2 Likes

Are you the author of it? Could you add some text to your post, why you posted the link, what's the purpose and so on? Just a random link isn't a good forum post.

Also, I don't think that that code is very idiomatic, e.g. the linear search function should not return i32, but instead Option<usize>. Don't fall into C habits :slight_smile:

And also I found at least one wrong output in the "Day of the Week" post. Better check that twice!

4 Likes

While we are at it, in general, there seem to be several anti-patterns in the Algorithms section (didn't check the others). E.g.:

  • taking &Vec as an argument instead of a slice or writing "".to_string() instead of String::new() in "Identity Matrix"
  • the superfluous returns in "Binary Search"
  • .ok().expect() (which loses the value of the Err variant) in "Singly Linked List"
  • Writing various String-returning display functions instead of implementing Display. Using line += &format!("Order: {}\n", mats[0]); that allocates superfluously, instead of the more efficient and simpler writeln!(line, "Order: {}", mats[0]).

In general, if you are writing educational material for others, you should make sure that your examples follow best practices and the idioms of the language, because those who are currently learning will copy the examples and they will use the solutions they see.

7 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.