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 ...
28
votes
1answer
976 views
Shift and merge numbers as in 2048 game code
I started to learn Rust last night. Given its parallelization capabilities, I thought a good starting point would be porting my C++ AI for 2048 to Rust.
This is the function implementing the shift ...
15
votes
1answer
230 views
Wanted a cat. Got lolcat
Wanna learn Rust? Ya rly!
I can haz FizzBuzz? No wai!
Gimme /bin/cat then. But rustc say LOL! Must handle teh err0rz!
Now iz ...
11
votes
1answer
221 views
Lotto simulator
With the recent craziness of the Powerball in the US, I got interested in building a little lotto simulator to see how frequently I could win with purchasing large amounts of tickets.
For those not ...
11
votes
0answers
396 views
Rust Brainfuck interpreter
I took the code from kostyas benchmarks for the Rust Brainfuck interpreter and tried to optimize it. There is also a discussion on Reddit about the poor performance of Rust in the Benchmark.
Before ...
10
votes
1answer
338 views
Tokenize s-expressions in Rust
I'm writing an s-expression tokenizer in Rust.
I have the following code written, but it is not idiomatic Rust - it is quite ugly. TokenizerI is simply an ...
10
votes
1answer
240 views
Rust language tag implementation
language-tags is my first crate, it is hosted on GitHub and I uploaded it to Crates.io. It parses language tags like en-US into useful parts, like language and ...
8
votes
2answers
139 views
Port of NLTK tokenizing code from Python to Rust
I'm working on a port of NLTK to Rust.
I am fairly new to Rust, so I wanted to post a small file to check if I was writing idiomatic Rust. I've included the original Python. The Python has docstrings ...
8
votes
1answer
911 views
K-Means in Rust
I have implemented for learning purposes a simple K-Means clustering algorithm in Rust. For those who are not familiar: you are given N points, say in the plane, ...
8
votes
1answer
158 views
Calculating word-wise CRC
This is a small program to calculate the CRC for an STM32 program image, compatible with the CRC on the STM32 hardware. It's a word-wise CRC, and the bin file is encoded as a series of 32 bit little ...
8
votes
1answer
142 views
Log sorting program
This is my first ever program written in Rust (after reading the book). It is small tool to sort all lines from stdin according to two criteria. First one is time ...
8
votes
1answer
114 views
Recursively pop the last node from a singly linked list
I am exploring different ways of implementing a linked list in Rust as a learning project. In one particular place, I've got some code that works properly, but it makes multiple calls to unwrap--I am ...
8
votes
1answer
73 views
Ntree: a reimplementation of the tree utility
tree is described as "a recursive directory listing command that produces a depth indented listing of files" on the homepage for its Linux implementation. I don't ...
7
votes
2answers
3k views
How can I find out why this Rust program to echo lines from stdin is slow?
Given the following Rust program:
...
7
votes
2answers
632 views
7
votes
1answer
250 views
Simple cat in Rust
I'm learning Rust, from a Python background, and while I've used languages like C and C++ in the (distant) past, system languages aren't really my specialty.
I would just like to know if my code is ...
7
votes
1answer
92 views
A Rusty implementation of CowSay
I'm making my first foray into Rust. I wanted to copy a fun and non utilitarian tool so I chose CowSay. It's not feature complete (CowSay has a lot of options) but it's a start.
My primary reasons ...
7
votes
1answer
228 views
Gamma function in Rust
The gamma function is one of a couple nice continuous extensions to the traditional factorial function. I used this Python program as a reference, which in turn, uses this Ada program. As the Ada ...
7
votes
1answer
85 views
Detecting two keys pressed in quick succession
My computer has been having this issue where when I press a key, two key presses get registered. The goal of this program is to detect the time delta between the two keys so that I can set an ...
7
votes
1answer
65 views
Implementation of UNIX `tee` in Rust
I am currently reading Michael Kerrisk's book, The Linux Programming Interface. This is one of the exercises from the end of chapter 4 (I'm working in Rust, not C).
A Rust implementation of the ...
7
votes
1answer
347 views
Binary Tree Implementation in Rust
To teach myself Rust, I implemented a naive binary tree with support for insert, delete and lookup operations as well as in-order iteration.
I'm still a little rusty (no pun intended) when it comes ...
7
votes
1answer
140 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
1answer
160 views
A rusty Bit Vector library
As an exercise to learn Rust I've decided to write a Bit Vector library, furthermore I also intend to use it later because my version can share slices of the bit vector between threads whereas the ...
7
votes
1answer
134 views
Project Euler #11“numbers in a grid” in Rust
To learn more about Rust, I implemented Project Euler #11 "Numbers in a grid". Contrary to some people, I prefer not having the actual data grid in my code, so I put it in a file, which I read in the ...
6
votes
3answers
264 views
Selection sort algorithm in Rust
I am just trying to use Rust so I will be thankful for all remarks and corrections:
...
6
votes
2answers
204 views
Jaccard distance between strings in Rust
The Jaccard distance between two sets is the size of their intersection divided by the size of their union. For example, the distance between {1, 2, 3} and ...
6
votes
1answer
152 views
Implementing a van Emde Boas tree in Rust
I wanted to implement a van Emde Boas Tree in Rust, to start learning the language. Much of my implementation is derived from the pseudo-code on wikipedia, with the exception that empty subtrees are ...
6
votes
1answer
222 views
Bitcoin algorithm BIP0039: Mnemonic code for generating deterministic keys
This is an implementation of BIP0039 in Rust (I used python-mnemonic as a guide). I'd like my first Rust program to be critiqued.
I would like to know if the program is structured correctly, if I've ...
6
votes
1answer
59 views
6
votes
2answers
138 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 ...
6
votes
1answer
110 views
General Fizzbuzz
I'm learning Rust now and created a program to solve the task General Fizzbuzz on Rosetta Code.
For example, given:
20
3 Fizz
5 Buzz
7 Baxx
where the first line ...
6
votes
1answer
54 views
Huffman encoding implementation for Unicode
I'm looking for a general review with emphasis on idiomaticness and error handling.
...
6
votes
1answer
59 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 ...
5
votes
2answers
86 views
X-up utility for EVE Online
I am learning Rust.
I also play EVE Online – a video game about internet spaceships. I decided that it would be fun to practice Rust by writing a simple utility to help me x up.
to x up (verb)
...
5
votes
1answer
302 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
1answer
123 views
Parsing/RPN calculator algorithm
I decided to try and complete the Parsing/RPN calculator algorithm from Rosetta Code in Rust. I'm still learning Rust and would appreciate feedback on my code.
...
5
votes
1answer
162 views
5
votes
1answer
63 views
Converting a 12h clock to 24h clock
I started picking up Rust on my free time, and I'm curious about what style errors have I made and where should I improve as a programmer.
The problem is from HackerRank and very simple: there is a ...
5
votes
2answers
92 views
Simple ASCII art in Rust
I stumbled my way through some Rust yesterday and today to make a simple ASCII art API. It can draw lines, circles, and a canvas.
...
5
votes
1answer
54 views
What is the idiomatic Rust way to write this naive JavaScript token scanner code fragment?
I am learning Rust and finding it quite a difficult but rewarding and fun challenge to learn how to write idiomatic and succinct, clean code in it.
I have written the following simple naive ...
5
votes
1answer
1k 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 ...
5
votes
1answer
39 views
Python-like enumerate and join
I'm new to Rust and trying to convert some Python to Rust. I have the following in Python:
...
5
votes
1answer
127 views
K-means clustering in Rust
I've implemented K-means clustering in Rust. It's my second Rust project (my first one is here: Randomly selecting an adjective and noun, combining them into a message)
I would like advice on ...
5
votes
1answer
110 views
Number-Guessing Game in Rust
I don't yet see a code review for a number-guessing game in Rust. Since I am just learning the language, and since the number-guessing game is part of the official Rust tutorial, I thought it would be ...
5
votes
1answer
52 views
Using parser_combinators to parse a string
I am playing with Rust, and am trying to write a simple parser.
I need to parse the string:
"0123,456789"
into a stucture:
...
5
votes
0answers
44 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 ...
4
votes
2answers
188 views
Netscape bookmark file generator
I started to learn Rust some time ago and I wonder if there is some way to write Rust code that is both concise and safe — in particular, avoiding unwrap(), casting ...
4
votes
2answers
136 views
Counting primes less than n
The following code was written to be a submission to this challenge on PPCG.
It uses this algorithm, the Meissal-Lehmer method. I follow the Wikipedia entry pretty naively, except I tried to memoize ...
4
votes
2answers
176 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 ...
4
votes
1answer
51 views
From a string of 3 numbers to 3 integers
I'm solving some puzzles to learn Rust. A problem I faced is to turn a string of 3 integers into 3 integers. I succeeded with the following example:
...
4
votes
1answer
31 views
Extract PNGs embedded in a file
My approach was to find each occurrence of the PNG's file signature followed by its end of file (EOF) and write the bytes between to a new file whose name is simply a counter starting at zero.
...