Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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
37 votes
1 answer
2k 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 ...
Jonas Schäfer's user avatar
34 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
  • 523
34 votes
1 answer
1k 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 ...
Pyfisch's user avatar
  • 661
25 votes
1 answer
5k views

Repository pattern in Rust

I'm looking to add a thin layer of abstraction for database interaction in my application. I'm not really looking for a full blown ORM or advanced query builder. I am familiar with Diesel, but its ...
kardeiz's user avatar
  • 571
24 votes
1 answer
667 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 ...
200_success's user avatar
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
17 votes
1 answer
9k 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 ...
Fabian Knorr's user avatar
15 votes
2 answers
4k views

Web crawler in Rust

I am learning Rust. I have written a web crawler that would scrape all the pages from my own blog (which is running on Ghost) and would generate a static version of it. Because of this, I'm not ...
rolisz's user avatar
  • 253
15 votes
0 answers
243 views

Download files in parallel

This module has a ensure_downloaded function which takes a slice of Urls. It downloads all of the urls to a local downloads ...
Winston Ewert's user avatar
14 votes
4 answers
7k views

Writing slice compare in a more compact way

I have this code snippet comparing two slice references: ...
JACK M's user avatar
  • 243
14 votes
1 answer
2k 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 ...
Tom Carrick's user avatar
13 votes
2 answers
3k views

Circular FIFO Buffer

I was bored the other day and got to wondering how I would implement a circular FIFO buffer in Rust. My goal was to create an implementation I could use on a bare metal microcontroller. This means no ...
RubberDuck's user avatar
  • 30.8k
13 votes
1 answer
418 views

(Lisp in (Rust))

I loved Norvig's Lispy, and made the first version of it in Rust, to learn Rust. I would love your thoughts :) A few specific questions: Is there a way to write ...
Stepan Parunashvili's user avatar
13 votes
1 answer
972 views

IPv6 parsing in rust

Here is code to parse an IPv6 address. An IPv6 address is 128 bits long. When represented in its printable form, its hextets (1 hextet == 16 bits) are represented as hexadecimal numbers, and are ...
little-dude's user avatar
12 votes
2 answers
5k views

How can I find out why this Rust program to echo lines from stdin is slow?

Given the following Rust program: ...
mkaito's user avatar
  • 229
12 votes
1 answer
2k 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, ...
Andrea's user avatar
  • 437
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
12 votes
1 answer
986 views

How Rusty is my generic union-find implementation?

I decided to implement a DisjointSet<T> data structure myself in Rust, with no dependencies except for std, for the ...
naiveai's user avatar
  • 166
12 votes
1 answer
424 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 ...
Pyfisch's user avatar
  • 661
11 votes
2 answers
7k views

Extracting the last component (basename) of a filesystem path

...
Sean Perry's user avatar
  • 1,199
11 votes
1 answer
2k 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 ...
erip's user avatar
  • 926
11 votes
1 answer
5k views

Dijkstra's algorithm in Rust

I'd love to get feedback on my first go at Dijkstra's algorithm in Rust: ...
Matthias Braun's user avatar
11 votes
1 answer
2k 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 ...
Jared Mackey'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
  • 203
10 votes
2 answers
260 views

Laptop battery level monitor for Linux

I come from a C background and am trying to learn Rust. I wrote my first Rust program, to check the battery level on my laptop and warn me if it's low/critical. It works fine, but I wrote it in a ...
John Moon's user avatar
  • 203
10 votes
1 answer
1k 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 ...
Dair's user avatar
  • 5,906
10 votes
2 answers
1k views

Fraction type in Rust

Inspired by another question here on Code Review, I decided to try implementing a Fraction type in Rust. Requirements: Able to be added, subtracted, multiplied, ...
Dan Ambrogio's user avatar
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
10 votes
1 answer
669 views

Advent of Code 2018 day 15 - Naive Rust program

I solved the Advent of Code problems last year in Python, and I wanted to learn a new language this year, so I decided to write up Part 1 of on of the hardest problems from last year - problem 15 - in ...
naiveai's user avatar
  • 166
10 votes
1 answer
156 views

Brainf*** interpreter in Rust

I'm learning Rust coming from an intermediate background in Python. I've completed the first 8 chapters of the book and I wanted a project that would solidify the concepts I learned, so I made a ...
EphraimRuttenberg's user avatar
10 votes
1 answer
191 views

Intcode computer in Rust

This is my first attempt to learn Rust by applying it for a problem that I assume is suitable for the language. It's the Intcode computer from https://adventofcode.com/2019. I've implemented all the ...
Nikola Kasev's user avatar
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
9 votes
3 answers
2k views

n-th Fibonacci number with memoization

I am learning Rust and decided to create a simple program to calculate n-th Fibonacci number. It uses a vector for memoization. The program works, but what would you suggest to improve here? Maybe ...
user4035's user avatar
  • 293
9 votes
2 answers
941 views

Selection sort algorithm in Rust

I am just trying to use Rust so I will be thankful for all remarks and corrections: ...
ceth's user avatar
  • 792
9 votes
2 answers
1k views

Binary adder implemented in Rust

I implemented a ripple carry adder in Rust. The function takes and outputs strings of 1s and 0s. How can I improve this ...
minseong's user avatar
  • 749
9 votes
1 answer
581 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 ...
WillW's user avatar
  • 193
9 votes
1 answer
288 views

Construct a performant sieve of Atkin in Rust

I have implemented the sieve of Atkin in Rust. It can find all primes till 1,000,000,000 in 4.5 s using 34.4 MiB on my 1.4 GHz machine. This is a direct implementation (with some optimisations made ...
tfpf's user avatar
  • 193
9 votes
2 answers
1k views

Multithreaded bogosort in Rust

For some quick context, I'm fairly new to Rust and decided to give myself a difficult-but-attainable task of implementing a sorting algorithm. I chose bogosort (or stupid-sort, shuffle-sort, whatever ...
LambBrainz's user avatar
9 votes
1 answer
142 views

Boggle solver in Rust - Looking for speedup

I recently made a boggle solver in Rust to compensate for the fact that I'm really bad at boggle. This has also been a good Rust learning experience. The code does what it's supposed to quite well but ...
tcallred's user avatar
  • 193
9 votes
1 answer
1k views

Traceroute implementation in Rust

I made this simple traceroute implementation using the libpnet library, which sends ICMP echo probes with an increasing time-to-...
confused00'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
8 votes
3 answers
409 views

Optimise Game of Life in Rust

I recently picked up Rust and was making a CLI for Conway's Game of Life. I got it working but, looking back at it, there are places it could be improved. The main one is the function that generates ...
myster's user avatar
  • 83
8 votes
2 answers
762 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
551 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 ...
erip's user avatar
  • 926
8 votes
2 answers
1k views

Solution to the Rustlings from_into exercise

I've got a working solution to the Rustlings from_into exercise (i.e. the code compiles and all the tests pass). The task required that I implemented the From trait ...
Kyle_S-C's user avatar
  • 233
8 votes
1 answer
358 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 ...
Nick Tomlin's user avatar
8 votes
1 answer
974 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.6k
8 votes
1 answer
838 views

Rust: Splitting a mutable slice into disjoint, but non-contiguous subslices

For some context, this is inspired by my attempt to solve this SO question. I have a mutably borrowed slice representing a 2D array, and I want to split the borrow such that I can access all the rows ...
FZs's user avatar
  • 183
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
368 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,560

1
2 3 4 5
18