Questions tagged [rust]

Rust is a systems programming language focused on three goals: safety, speed, and concurrency. It maintains these goals without needing a garbage collector, making it a useful language for a number of use cases other languages aren't good at: embedding in other languages, programs with specific space and time requirements, and writing low-level code, like device drivers and operating systems.

Filter by
Sorted by
Tagged with
0 votes
1 answer
125 views

Advent of Code 2020 - Day 2: validating passwords

Previous: Advent of Code 2020 - Day 1: finding 2 or 3 numbers that add up to 2020 Next: Advent of Code 2020 - Day 3: tobogganing down a slope Problem statement I decided to take a shot at Advent of ...
user avatar
  • 9,047
10 votes
1 answer
4k views

Binary trees in Rust: iterators

This is a follow-up to Basic binary tree manipulation in Rust, where Shepmaster suggested that I implement the Iterator trait for the binary tree. This ended up ...
user avatar
  • 1,169
4 votes
1 answer
180 views

Naive convex hull from Algorithms in a Nutshell book

I am working through the book Algorithms in a Nutshell by George T. Heineman and trying to translate the pseudocodes into Rust. Here is a naive convex hull algorithm: ...
user avatar
  • 1,429
4 votes
2 answers
340 views

Incremental Sieve of Eratosthenes using iterators

I am in the process of learning Rust and am still having some issues with borrowing and ownership. I find myself trying to borrow mutable references that are already borrowed as immutable references ...
user avatar
  • 201
3 votes
1 answer
123 views

Advent of Code 2016: Day 1, Part 1

I'm working through Advent of Code 2016 in Rust. The prizes go to the swift, but I'm aiming for well-written code. This is Day 1. To summarize the problem statement, given a instruction string of ...
user avatar
1 vote
1 answer
58 views

Advent of Code 2020 - Day 3: tobogganing down a slope

Previous: Advent of Code 2020 - Day 2: validating passwords Problem statement I decided to take a shot at Advent of Code 2020 to exercise my Rust knowledge. Here's the task for Day 3: Day 3: ...
user avatar
  • 9,047
1 vote
1 answer
362 views

Divide and conquer approach in search for max element

Continuing the Algorithm in a Nutshell series, here is the code: ...
user avatar
  • 1,429
27 votes
2 answers
22k views

Calculate mean, median, and mode in Rust

I'm learning Rust using The Rust Programming Language. I'm trying the assignment at the end of chapter 8 — Hash Maps. The task is: Given a list of integers, use a vector and return the mean (...
user avatar
  • 453
17 votes
3 answers
2k views

Shoe shine shop model in Rust

I'm learning Rust and a few questions did arise during translation of my C++ code to Rust. There are comments in Rust code I'd like to be answered. Is there an idiomatic way to solve this task? The ...
user avatar
  • 403
10 votes
2 answers
2k views

Recursive Fibonacci in Rust with memoization

I'm trying to come up with an "elegant" way of calculating Fibonacci for number in Rust, using recursion and memoization (self-imposed requirements). This is what I have so far: ...
user avatar
4 votes
0 answers
125 views

SHA256 implemented in Rust

I just finished making an implementation of a SHA256 hashing function (https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf) in Rust and I was looking for some feedback. As far as I can tell it ...
user avatar
9 votes
3 answers
5k views

Simplest way to write "FizzBuzz" in Rust

Can you write an a simpler Rust fizzbuzz program than I have? Use my output or the spec: Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of ...
user avatar
  • 255
7 votes
2 answers
2k views

Insertion sort in Rust

Here is the code: ...
user avatar
  • 1,429
6 votes
1 answer
1k views

Simple Rust Webserver

I started learning Rust today and for my first project created a simple webserver. I don't have a clear vision about Rust programming and I tried to write it with my previous knowledge in Python and ...
user avatar
  • 423
8 votes
2 answers
1k views

Implement a generic Fibonacci sequence in Rust without using Copy trait

I'm trying to learn Rust and am a beginner. How does one go about implementing a generic version of the Fibonacci sequence without using Copy trait in Rust? My code ...
user avatar
  • 83
6 votes
1 answer
2k views

Converting a hexadecimal string to a binary string using Rust pattern matching lookup

I am getting started in Rust, and as a part of my first exercise, I decided to write a small program that converts a hexadecimal string to a binary string using a pattern matched lookup. I would ...
user avatar
  • 1,193
5 votes
1 answer
2k views

Hex string to Base64

The base64 decode algorithm is taken directly from Base64 wiki page. This exercise is meant to help me learn Rust, so any pointers in that general direction are very welcome. :) ...
user avatar
  • 175
5 votes
1 answer
581 views

Josephus permutation

This problem is taken from the book Introduction to Algorithms, Third Edition By Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein: We define the Josephus problem as ...
user avatar
  • 2,974
4 votes
1 answer
147 views

port of my c++ timer queue to rust

This is part of a larger c++ project that I want to migrate to rust (a pdp11 emulator). This is one of the gnarliest bits of the c++ code so I thought I would start with it - its also self contained ...
user avatar
  • 771
8 votes
1 answer
756 views

The rusty Sieve of Eratosthenes

To get familiar with the Rust language I've decided to implement the method of Sieve of Eratosthenes to find primes up to a number N. I have created the following code that both prints the prime ...
user avatar
  • 10.6k
8 votes
2 answers
406 views

Rust Echo Command Implementation

I'm just starting out in Rust and I find the concept of ownership confusing so I wrote an implementation of the echo command. I would like to know if I could have ...
user avatar
7 votes
2 answers
2k views

MergeSort in Rust

I've just started learning Rust and put together this working MergeSort implementation. Wondering what I've overlooked and what I could improve. I couldn't figure out a cleaner way to deal with the <...
user avatar
7 votes
1 answer
929 views

Binary trees in Rust: more iterators! (non-consuming variant)

This is a follow-up to Binary trees in Rust: iterators, where Shepmaster suggested that I implement a non-consuming iterator. This was relatively straightforward. I chose to mirror the design of the ...
user avatar
  • 1,169
7 votes
2 answers
2k views

Fahrenheit and Celsius converter in Rust

I made a program that converts between Celsius and Fahrenheit. Is there any way that I could make this code more efficient and cleaner? ...
user avatar
7 votes
2 answers
241 views

Rust Novice's Tic Tac Toe

Introduction I am a Rust novice. So far, I have finished reading the first 15 chapters of The Rust Programming Language (a.k.a. the book). Here's my first big Rust project — Tic Tac Toe. ...
user avatar
  • 9,047
7 votes
1 answer
138 views

Randomly selecting an adjective and noun, combining them into a message

This is my first Rust program. I have previously written a lot of Python, and some C. I would like some advice on whether I am doing things idiomatically, and any improvements I could make! I also ...
user avatar
  • 215
6 votes
1 answer
2k views

Transposing characters in a string

I want to create a function that takes a string and returns an array of versions of it in which always one pair of characters is transposed (swapped). I came up with this: ...
user avatar
  • 412
6 votes
1 answer
305 views

Huffman encoding implementation for Unicode

I'm looking for a general review with emphasis on idiomaticness and error handling. ...
user avatar
  • 2,974
5 votes
1 answer
928 views

Basic binary tree manipulation in Rust

The goal here is to implement a basic binary tree with values only on leaves, with depth, mirror, and ...
user avatar
  • 1,169
5 votes
0 answers
794 views

Recursive factorial calculations in Rust

I am trying to calculate very large factorials. I am looking to speed it up as 10000! takes approximately a minute and a half. ...
user avatar
5 votes
0 answers
145 views

Multiple rusty Sieves of Eratosthenes

To get more familiar with the multi-threading aspects in the Rust language I decided to multi-thread my earlier implementation of The rusty Sieve of Eratosthenes. I have to say that it is probably in ...
user avatar
  • 10.6k
5 votes
1 answer
152 views

Shoe shine shop model in Rust and C++ - Follow-up

I've just refactored my Rust and C++ code which simulates the shoeshine shop model from this question. What else can be improved? C++: ...
user avatar
  • 403
5 votes
2 answers
485 views

Edit distance implementation

This problem is taken from the book Introduction to Algorithms, Third Edition By Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein: In order to transform one source string ...
user avatar
  • 2,974
4 votes
1 answer
156 views

Advent of Code 2021: day 1

I am doing the Advent of Code challenge to learn Rust (obviously there may be spoilers if you still want to do the challenge). The instructions are too long to include verbatim so I will link them and ...
user avatar
4 votes
1 answer
115 views

Language tokens library

This may seem a little small, but it's actually a self-contained crate in my project. This crate contains definitions for the source tokens in the language I'm working on, Nafi. As of current, it's ...
user avatar
  • 1,924
4 votes
0 answers
83 views

Bit Vector implementation

Looking for a general review. ...
user avatar
  • 2,974
2 votes
1 answer
94 views

Rust GitHub repository downloader

I made a little program that allows users to download a local copy of all their GitHub repositories for backup purposes. I've tried to write idiomatic Rust code, but I'm sure there are ways I could ...
user avatar
  • 329
2 votes
1 answer
87 views

Pseudo-random number generator & password generator

I've started learning Rust and decided to implement something on my own from scratch. I've implemented a PRNG and I use it to generate random passwords. Project tree: ...
user avatar
2 votes
1 answer
713 views

Z^m number system in Rust

A \$Z^m\$ number system includes integers in the interval \$[0, m)\$ when \$m > 0\$ or \$(m, 0]\$ when \$m < 0\$. The code defines a trait Mod to represent ...
user avatar
  • 1,429
2 votes
1 answer
956 views

Invoking function stored in a struct using Rust

I'm new to Rust, and I'm writing a basic command line input parser as a learning exercise. Commands entered on the command line are evaluated using the Cmd struct ...
user avatar
2 votes
0 answers
543 views

Rust exercise department employee management

Working my way through the second edition of the Rust Programming Language and did the exercise at the end of ch 8: Using a hash map and vectors, create a text interface to allow a user to add ...
user avatar
2 votes
1 answer
151 views

Small stack based language in Rust

I made a small stack-oriented language in Rust. It tries to run anything it is given. To elaborate: Division by zero gives zero. If there is nothing on the stack and a request is made that involves ...
user avatar
  • 5,754
2 votes
1 answer
853 views

Convert hex to base64 (Cryptopals challenge 1)

I've been spending some time learning Rust and I came across the Cryptopals Challenges. This is my implementation of challenge 1 Convert hex to base64 The string: ...
user avatar
  • 30.7k
1 vote
0 answers
61 views

Incremental Sieve of Eratosthenes using unstable generators [duplicate]

I am in the process of learning Rust and am still having some issues with borrowing and ownership. I find myself trying to borrow mutable references that are already borrowed as immutable references ...
user avatar
  • 201
0 votes
1 answer
100 views

Advent of Code 2020 - Day 1: finding 2 or 3 numbers that add up to 2020

Next: Advent of Code 2020 - Day 2: validating passwords Problem statement I decided to take a shot at Advent of Code 2020 to exercise my Rust knowledge. Here's the task for Day 1: Day 1: Report ...
user avatar
  • 9,047