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.
175
questions with no upvoted or accepted answers
15
votes
0
answers
254
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 ...
8
votes
1
answer
378
views
Metropolis Monte Carlo Sampler in Rust
the following is an implementation of the standard Metropolis Hastings Monte Carlo sampler. You can read more about it here.
At the end I am going to give you a link to the Rust playground, so you ...
6
votes
0
answers
257
views
All pairs/Cartesian multiplication of iterators in rust
crustaceans!
This is my attempt at creating an all_pairs operation for rust iterators. The code has to generate a new iterator which, when iterated, produces all ...
6
votes
0
answers
101
views
Chapter 8 Challenge: Add employee names to a department
The boring but exciting challenge:
Using a HashMap and HashSet, create a text interface to allow a user to add employee names ...
6
votes
0
answers
151
views
Efficiently generate distinct subsets which sum to a particular value
Related: Find all distinct subsets that sum to a given number
This code is supposed to efficiently generate all subsets of a list such that the subset's values sum to a particular target value. For ...
6
votes
0
answers
178
views
Simple-ish Rust implementation of 'cat'
I've seen some other implementations of cat (even in Rust) on this site, but none attempted to completely implement the GNU cat CLI as far as I can tell. This version that I am developing is complete (...
6
votes
0
answers
300
views
Generating integer partitions
I've tried to implement integer partition algorithm as described in blogpost below (author implemented it in Python):
Generating integer partitions
I'm still trying to learn best practices in ...
6
votes
0
answers
197
views
Character-based transitions (part of a lexer)
As part of my prep for the Code Review community-challenge (which looks like it will be Write your own programming language), I've been working on an LL(1) lexer generator in Rust.
Yes, lexer ...
5
votes
0
answers
41
views
Procedural macro to derive de/serialization trait from/to little endian bytes
I wrote a trait library that allows the de-/serialization of data structures from/to little endian bytes 1.
For it I now wrote my first procedural macro 2 to be able to derive the traits ...
5
votes
0
answers
54
views
after initial r*view here is a rewrite of my c++ timerqueue ported to rust
Purpose. Provides a background task queue so that code can ask for a function to be run at a specified point in the future. They indicate what to run (a closure) and when to run it (also a name just ...
5
votes
0
answers
470
views
recursive-file-watcher in rust
hello guys i made a file watcher in rust using notify crate that watches a directory and if it detects file changes it will copy all of the files within the directory to another directory,i wanted you ...
5
votes
0
answers
286
views
almostIncreasingSequence
This is assignment from codesignal:
Given a sequence of integers as an array, determine whether it is possible to obtain a strictly increasing sequence by removing no more than one element from the ...
5
votes
0
answers
178
views
Tetris clone in Rust using specs
In order to get a hang of the ECS paradigm of game making, I decided to try my hand at making a clone of Tetris. I am using the specs crate for Rust in order to ...
5
votes
0
answers
938
views
A multithreaded, growable vector with immutable elements, which has wait-free reads
Disclaimer for future readers: We experimented around with a similar approach at HASH. The linked Pull Request is working.
I wrote a small vector with a few lines of unsafe Rust.
The idea is to have ...
5
votes
0
answers
237
views
Drawing the Mandelbrot with multiple threads in rust
The code below draws the mandelbrot set for { z | z∈ ℂ, -2.2 ≤ Re(z) ≤ 0.6, -1.4 ≤ Im(z) ≤ 1.4} into a 300×300px png image. For each pixel,
if the sequence {zi} is found to ...
5
votes
0
answers
439
views
HashMap exercise, Rust book Ch.8
I'm learning Rust by learning the Rust programming language book. I'm now implementing the solution for the third challenge.
Using a hash map and vectors, create a text interface to allow a user to ...
5
votes
0
answers
192
views
Huffman encoding in Rust
An implementation of Huffman encoding / decoding as a learning exercise. I'm still new to Rust, so any tips about making things more natural for the language are appreciated.
...
5
votes
0
answers
2k
views
Converting an absolute Path to a relative one
I've this code that I use in some tool, and I wonder if it can be improved:
...
5
votes
0
answers
164
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
0
answers
430
views
Simple graph in Rust
I have written simple code to construct a graph, but I think there are too many different types for such a simple task.
In this code I need to store Node structs ...
5
votes
0
answers
895
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.
...
4
votes
0
answers
78
views
Implementation of Kirkpatrick-Seidel convex hull algorithm and comparing against Jarvis-March
Introduction
I wanted to implement the Kirkpatrick-Seidel(KPS) convex hull algorithm and chose Rust as my language. I referred to the original KPS paper and tried to implement as closely it as ...
4
votes
0
answers
70
views
A safe building block for self-referential structs in Rust, without macros
I recently had this (admittedly slightly crazy idea) on how to design a building block that can be used in safe Rust to build self-referential structs. Unlike gsrs or selfref it works completely ...
4
votes
0
answers
119
views
A simple local API proxy
Recently I needed to support someone who wanted to ingest some data from on of our API's but had tooling that struggled with the authentication bit. While I'm sure there are some off-the-shelf ...
4
votes
0
answers
323
views
Generic Monte Carlo Tree Search implementation in Rust
I'm working on a project where I need a strong AI for a combinatoric game, and decided to go with Monte Carlo Tree Search because the specific game will be original to the project - no good heuristics ...
4
votes
0
answers
112
views
Barebones DNS Client in Rust
I'm starting to learn about networking and as a project I am building a really simple DNS client in Rust.
Functionality to start was just to take a command line domain argument and sending a DNS A ...
4
votes
0
answers
532
views
A safe type-erased Fn Pointer in rust that can be used to call associated and regular function
I am implementing a callback method to replace the use of generics.
For maximum performance, it is not allowed to use Box and I also don’t want to use ...
4
votes
0
answers
143
views
LeetCode 1632: Rank Transform of a Matrix in Rust
This is a problem-solving code for LeetCode 1632.
Given an \$m \times n\$ matrix, return a new matrix answer where
...
4
votes
0
answers
158
views
Small generic helper library for working with recursive data structures
I've written a small rust library that solves rust's problems with using recursive data types (e.g, linked lists).
using the library, you can use ...
4
votes
0
answers
87
views
Fast compression using a thread pool
This is my latest effort on RFC 1951 compression ( the widely-supported compression standard ) in Rust. It uses 2 extra threads to compute the LZ77 matches and the checksum in parallel with the ...
4
votes
0
answers
222
views
Tar file utility - Rust
I've been working on building a Rust version of GNU tar following the spec here.
As of right now, I've got the binary accepting a single argument, the path to the file/directory to tar, which is ...
4
votes
0
answers
295
views
Function composition in rust
In rust fp-core crate there is a compose function, but it is very limited for my liking.
So I made a macro which uses the function composition syntax of Haskell.
I would like to know why fp-core didn'...
4
votes
0
answers
120
views
Implement a micro service in Rust
Last year I tried to implement a micro service architecture in Rust. It was asked as a homework question in an employment interview process to be completed in a few days. The imagined use case was a ...
4
votes
0
answers
274
views
Rust Iterative and Recursive Merge Sort Implementation
I'm in the process of learning both Rust and algorithms after primarily focusing on web development. As such I've had a go at implementing merge sort both iteratively and recursively.
I've looked for ...
4
votes
0
answers
125
views
Molecular .pdb File Reader in Rust
I am new to rust and wanted to get going with a medium-sized project to help learn. I've settled on creating some basic quantum mechanics code which starts with this bare-bones file reader. It takes a ...
4
votes
0
answers
166
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 ...
4
votes
0
answers
382
views
Wait free triple buffer primitive
I'm trying to write a triple buffer that's wait free for a update + render loop after being bitten by lock starvation one too many times (on a different project, using a library).
For reference, a ...
4
votes
0
answers
600
views
Simple routing in Rust
After my last attempt, I started to learn Rust again. This time I wrote a simple HTTP router. I would appreciate it if you could help me to fix my mistakes.
Here is the link of the repository
main....
4
votes
0
answers
60
views
Translating Python to Rust: reading a Salesforce ID from a string
As a first project in Rust, I'm translating an existing, working piece of Python code. This code's purpose is to convert a 15-character Salesforce Id (which is guaranteed to be ASCII, exactly 15 bytes ...
4
votes
0
answers
470
views
Move-generation for chess in rust
In the last couple of days I have been programming a chess move generator in Rust from scratch. While it's intent is to be later used in a fully functional engine, where the speed of the move-...
4
votes
0
answers
291
views
Collatz fractal in Rust
Among the many fractals, there is Collatz Fractal based on a complex extension of:
$$f(x) = \left\{
\begin{array}{ll}
\frac{x}{2} \space \text{if even} \\
3x + 1 \space \text{if odd}
\end{array}
\...
4
votes
0
answers
263
views
Bisection and Newton's method for finding a root of an equation
In an attempt to learn Rust, I've written up implementations of the bisection method and Newton's method for finding roots of an equation. Both methods come in two variants: the first one searches for ...
4
votes
0
answers
721
views
Finite Automata stub in Rust
I wrote a finite automata implementation in C years ago. C's access to mutable, unsafe, raw pointers made it quite simple for me to link/relink the states of a finite automata.
I read the official ...
4
votes
0
answers
56
views
Parsing λ-terms using a very simple grammar
This is my first Rust program. It parses a string into a λ-term using a very simple grammar.
Please evaluate style and use of ownerships / borrowing.
...
4
votes
0
answers
2k
views
Red-black tree in Rust
Although I have done a few toy projects in Rust, I haven't really done anything related to tedious memory management tasks. So I set out to create a database with the help of the project 500 lines or ...
4
votes
0
answers
370
views
Knapsack 0-1 in Rust
Here is an implementation of Knapsack in Rust. How could it be improved?
Some things I have already spotted:
What would be the best way to extract result? Is using an option preferred unwrapping the ...
4
votes
0
answers
445
views
Lexer with a parser combinator
A follow up to my previous question which was on the token library that this lexer produces a stream of.
View the full project, the tokens library, the parser combinator library, or this lexer ...
4
votes
0
answers
3k
views
Read and Write TCP Streams
I am working on an in memory on disk cache and am using TCP to send data between the client and server
Testing locally things seem to be working alright. I've written a small test client so I can ...
4
votes
0
answers
94
views
Bit Vector implementation
Looking for a general review.
...
4
votes
0
answers
251
views
Heap sort in Rust
The tests are taken from this answer on an insertion sort in rust question.
The algorithm is taken from Algorithms in a Nutshell (2nd Edition).
I'm not looking at crazy performance, the goal being ...