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
144 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 ...
L. F.'s user avatar
  • 9,550
10 votes
1 answer
5k 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 ...
wchargin's user avatar
  • 1,169
4 votes
1 answer
199 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: ...
qed's user avatar
  • 1,419
4 votes
2 answers
419 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 ...
kyle's user avatar
  • 183
3 votes
1 answer
156 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 ...
Matthew Piziak's user avatar
1 vote
1 answer
68 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: ...
L. F.'s user avatar
  • 9,550
1 vote
1 answer
395 views

Divide and conquer approach in search for max element

Continuing the Algorithm in a Nutshell series, here is the code: ...
qed's user avatar
  • 1,419
33 votes
2 answers
36k 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 (...
PEAR's user avatar
  • 513
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 ...
rogday's user avatar
  • 403
12 votes
2 answers
4k 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: ...
Armando Pérez Marqués's user avatar
10 votes
2 answers
1k views

Beginner Rust Todo app

I am trying to use the practices that I have learnt from the rust book. Any advice is welcome. Please feel free to be as nitpicky as possible. ...
Doruk's user avatar
  • 181
9 votes
3 answers
7k 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's user avatar
  • 255
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 ...
skanur's user avatar
  • 83
8 votes
2 answers
367 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. ...
L. F.'s user avatar
  • 9,550
8 votes
1 answer
964 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 ...
skiwi's user avatar
  • 10.7k
8 votes
2 answers
742 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 ...
Genuinebyte's user avatar
8 votes
2 answers
4k 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? ...
roberthayek's user avatar
7 votes
2 answers
93 views

rustymines - a mine sweeping game with a shenanigan

I am learning Rust for about a week now. I just finished my first little working project, a mine sweeping game. The game comes with a little extra feature, namely old, broken (rusty) mines, that will ...
Richard Neumann's user avatar
7 votes
1 answer
4k 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 ...
sc_ray's user avatar
  • 1,213
7 votes
1 answer
206 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 ...
lochsh's user avatar
  • 215
7 votes
1 answer
3k views

Insertion sort in Rust

Here is the code: ...
qed's user avatar
  • 1,419
7 votes
1 answer
1k 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 ...
wchargin's user avatar
  • 1,169
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 <...
Christopher Zehner's user avatar
6 votes
1 answer
3k 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: ...
BMBM's user avatar
  • 412
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 ...
Saeed M.'s user avatar
  • 423
6 votes
1 answer
344 views

Huffman encoding implementation for Unicode

I'm looking for a general review with emphasis on idiomaticness and error handling. ...
MAG's user avatar
  • 2,934
5 votes
2 answers
586 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 ...
MAG's user avatar
  • 2,934
5 votes
1 answer
159 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++: ...
rogday's user avatar
  • 403
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. :) ...
sYnfo's user avatar
  • 175
5 votes
0 answers
160 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 ...
skiwi's user avatar
  • 10.7k
5 votes
1 answer
1k 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 ...
wchargin's user avatar
  • 1,169
5 votes
0 answers
894 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. ...
Jared Mackey's user avatar
5 votes
1 answer
720 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 ...
MAG's user avatar
  • 2,934
4 votes
0 answers
165 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 ...
user668074's user avatar
4 votes
1 answer
119 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 ...
CAD97's user avatar
  • 1,944
4 votes
0 answers
90 views

Bit Vector implementation

Looking for a general review. ...
MAG's user avatar
  • 2,934
4 votes
1 answer
187 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 ...
NeRoboto's user avatar
  • 143
4 votes
1 answer
199 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 ...
pm100's user avatar
  • 791
3 votes
0 answers
647 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 ...
stevensonmt's user avatar
2 votes
1 answer
78 views

Smoothed Particle Hydrodynamics in Rust

So I'm simultaneously learning both Rust and Smoothed Particle Hydrodynamics. I've been using this video from AMD as a reference and the provided smoothing kernels. At this stage, I've not optimised ...
ScottishTapWater's user avatar
2 votes
1 answer
117 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: ...
Padriton's user avatar
2 votes
1 answer
1k 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 ...
John Stritenberger's user avatar
2 votes
1 answer
164 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 ...
Sky's user avatar
  • 329
2 votes
1 answer
995 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: ...
RubberDuck's user avatar
  • 30.8k
2 votes
1 answer
721 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 ...
qed's user avatar
  • 1,419
2 votes
1 answer
184 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 ...
Dair's user avatar
  • 5,864
1 vote
0 answers
64 views

Web scraper to retrieve articles from HTML embedded in JavaScript

I wrote a web scraper library to parse articles from HTML documents where they are encoded in a JSON object in JavaScript element. I wrote the example HTML file and ...
Richard Neumann's user avatar
0 votes
1 answer
106 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 ...
L. F.'s user avatar
  • 9,550