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
9
votes
1answer
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 ...
4
votes
2answers
175 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 ...
4
votes
1answer
154 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: ...
3
votes
1answer
107 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 ...
1
vote
1answer
289 views

Divide and conquer approach in search for max element

Continuing the Algorithm in a Nutshell series, here is the code: ...
17
votes
3answers
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 ...
4
votes
0answers
81 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 ...
6
votes
1answer
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 ...
8
votes
3answers
2k 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 ...
7
votes
2answers
978 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 ...
5
votes
1answer
465 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 ...
5
votes
1answer
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. :) ...
5
votes
1answer
239 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 ...
8
votes
2answers
243 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 ...
7
votes
1answer
508 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 ...
7
votes
2answers
886 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? ...
7
votes
2answers
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 <...
7
votes
1answer
122 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 ...
6
votes
0answers
690 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. ...
6
votes
2answers
2k views

Insertion sort in Rust

Here is the code: ...
6
votes
1answer
222 views

Huffman encoding implementation for Unicode

I'm looking for a general review with emphasis on idiomaticness and error handling. ...
6
votes
1answer
962 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: ...
5
votes
0answers
100 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 ...
5
votes
1answer
790 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 ...
5
votes
2answers
401 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 ...
5
votes
1answer
141 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++: ...
5
votes
1answer
810 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 ...
4
votes
1answer
109 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 ...
4
votes
0answers
81 views

Bit Vector implementation

Looking for a general review. ...
3
votes
1answer
90 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 ...
2
votes
0answers
366 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 ...
2
votes
1answer
279 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 ...
2
votes
1answer
411 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: ...
2
votes
1answer
690 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 ...
2
votes
1answer
65 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 ...
2
votes
1answer
115 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 ...
1
vote
0answers
56 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 ...