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.
871 questions
2
votes
1
answer
62
views
File list and monitor
I recently was given a take home assignment for a job interview. The task was specified like so:
...
4
votes
1
answer
109
views
Simple Sieve of Eratosthenes
I've implemented this version of the Sieve of Eratosthenes in Rust, with inputs. I'm mostly pleased with it, but want to know if the input logic can be simplified, and if the sieve itself can be ...
5
votes
1
answer
63
views
Generating random bytes
I implemented a simple function that generated random bytes Vec<u8> with given n size. Then I wondered how can I optimize ...
4
votes
1
answer
67
views
LeetCode Rust solution for the Sliding Puzzle problem #773
Here is the solution to the LeetCode Sliding Puzzle Problem #773. The problem is to find the shortest solution for a 3 x 2 sliding puzzle.
I would appreciate any ideas to improve this code. But it's ...
3
votes
0
answers
39
views
LeetCode Rust solution for the Flip Columns problem #1072
Here is the solution to LeetCode Problem #1072.
The problem is to find the maximum number of rows in a matrix where all the values can be made equal after some columns are flipped. It's assumed that ...
2
votes
0
answers
80
views
MIDI router in Rust
I am working on a small MIDI router application for the Jack audio connection kit in Rust. The goal of the application is to route MIDI signals from an instrument to one or multiple applications in ...
2
votes
1
answer
167
views
Mini-Memcached server implementation in Rust
I tried to implement a limited version of Memcached. This is the first time I used multi-threading / async in rust so I had a lot of trouble implementing the part where we establish connections and ...
6
votes
2
answers
107
views
Splitting Rust Strings into variables
I'm learning Rust and I'd like advice on how to make my code more idiomatic. I have a set of entries that are colon separated string-number pairs, a name and a size, like so:
...
-1
votes
0
answers
43
views
Simulating Conway's Game of Life
I'm a novice with Rust, with a background in C++, and I'm trying to implement an efficient program for simulating Conway's game of life.
I would like to eliminate redundant copying, and to make it ...
7
votes
1
answer
78
views
Recursive descent JSON parser in Rust
I've written a simple recursive descent JSON parser in Rust. It just reads in a JSON file and prints the syntax tree to the terminal. I'm still learning Rust, and I'd appreciate any review/feedback. ...
0
votes
0
answers
39
views
Todo list manager
I've completed a roadmap.sh project: https://roadmap.sh/projects/task-tracker/
It's my first rust project. So there's probably a lot of things that could be done in a more idiomatic way.
It's a CLI ...
6
votes
2
answers
1k
views
Program to find three cubes that sum to a fourth cube
I'm writing a Rust program that finds the "first five cubes that can be written as the sum of three distinct nonzero cubes", e.g. 216 = 6^3 = 3^3 + 4^3 + 5^3. The function looks like this:
<...
6
votes
1
answer
113
views
Mini auto-shooter game in Rust
I made a little game in Macroquad. You are a circle with a gun that shoots automatically at other enemies. The enemies follow you around and your goal is to dodge them. The game looks like this:
...
1
vote
1
answer
23
views
Basic Hybrid Logical Clock in Rust Performance Improvements?
I needed a very basic hybrid linear clock implementation for a project implementing MVCC. It gives me a perfectly incrementing clock that I can use to compare timestamps that can handle high load ...
4
votes
0
answers
68
views
Combinator Expression Parser in Rust
I am writing a parser/evaluator for combinator expressions. My end goal with this project is (attempt to) solve AoC 2024 using only combinatory logic.
I am representing combinator expressions as ...
4
votes
0
answers
38
views
Simple calculator app in Rust
To learn about Rust and parsing, I wrote a simple calculator that can solve problems involving the four basic operations (+, -, *, /) as well as exponentiation. For the sake of simplicity and ...
1
vote
0
answers
37
views
Wraps C Executable with Rust FFI
This Rust executable passes its arguments - including the executable's path - to an existing C program via Rust's FFI.
From a human's perspective, invoking the built executable should be identical to ...
1
vote
0
answers
37
views
N-Body simulator in Rust implementing Barnes Hut and Leapfrog
I have written a N-body simulator in Rust implementing Barnes Hut algorithm and Leapfrog integrator.
My code seems to work fine, but I'd like to review on techniques which can improve performance ...
4
votes
1
answer
156
views
Poker Lite (AOC 2023 Day 7) using structs wrapped in an enum
I've been trying to learn Rust by working through Advent of Code 2023, specifically for day 7, part 1, here. It's Poker Lite:
You're given a list of hands. The input is formatted as ...
2
votes
1
answer
241
views
Roman Numerals Look and Say in rust (BIO 2020 Q1)
I was practicing question 1a of the British Informatics Olympiad 2020 past paper.
The Roman look-and-say description of a string (of Is, Vs, Xs, Ls, Cs, Ds and Ms) is made by taking each block of ...
3
votes
1
answer
96
views
Type-state pattern and state management for credentials struct used with Spotify web API
I am implementing authentication with the Spotify web API as part of a larger project. Yes I know there are already crates that can handle it for me but that is no fun. I am implementing the auth code ...
4
votes
1
answer
73
views
Local Discovery Protocol v4
The following is a minimal implementation of syncthing's Local Discovery Protocol.
I am looking for feedback on:
Improving the efficiency and reliability of the code.
Best practices for this kind of ...
0
votes
2
answers
91
views
Convert uppercase to title case
Following is my rust function to convert uppercase to titlecase (without removing the underscore). although I am able to achieve my goal but I don't think this is a good solution. Ignoring the nested ...
2
votes
1
answer
67
views
Rust code to print shell prompt
I'm new to Rust, and this is my first successful significant Rust code. It prints a prompt(which is technically a string) to the console.
I'm struggling with concepts like ...
7
votes
2
answers
246
views
Bit manipulation to find a monochromatic clique on k vertices knowing all on k-1 vertices
I have a very hot segment of code in a large project. I've extracted the relevant segment and a toy example to illustrate it.
The project involves an unavoidable combinatorial explosion related to ...
3
votes
2
answers
139
views
Actix Web middleware to limit endpoint requests
I would like to publish my first package to crates.io - it is a simple library crate that allows one to rate limit server endpoints.
...
1
vote
0
answers
63
views
Solving upper triangular matrix-vector equation in Rust
Most linear algebra libraries written for Rust, e.g. nalgebra or ndarray have type or trait requirements that mean their ...
4
votes
1
answer
372
views
Dependency Injection - Actix Web - Rust
I want to know how would I go about architecting an MVC architecture using actix-web.
I have a user_service which requires ...
3
votes
1
answer
92
views
Compare and merge sets from unstructured variables for automatic differentiation
I have developed an automatic differentiation module for my software. Usually AD comes in two forms; forward mode or reverse mode and very clever approaches, beyond me, might mix both. Typically the ...
3
votes
1
answer
49
views
Benchmarking type generic algorithms on type heterogenous problem sets in Rust
I need to benchmark the different code generations of a generic function in rust, for different type parameters. I ran upon this when developing differential equation solvers using ...
2
votes
1
answer
64
views
Can I use only mutex and condition variable Instead of the Banker's Algorithm?
I've been studying the Banker's Algorithm and was curious if I could implement a similar resource management system using only Mutex and Condvar. The code I wrote is a synchronization program that ...
2
votes
1
answer
130
views
Simulated Annealing Variant for Conway's 99 Conjecture
I have made an algorithm that simplifies the "temperature" aspect of simulated annealing in an attempt (for fun) to solve Conway's 99 Conjecture. A brief explanation of Conway's 99 ...
4
votes
1
answer
396
views
Better way to add attributes to an enum in Rust for code scalability
I watched a YouTube video (https://www.youtube.com/watch?v=z-0-bbc80JM) talking about the power of enums in rust for data modelling. In the video, there's an example of a state machine of a simple ...
2
votes
0
answers
45
views
Alternative to Arc<Mutex> and clone() when using multiple variables in a callback
I'm new to Rust, and I'm working on an exercise to develop a parking lot system using the Raspberry Pi GPIO and socket.io.
After some struggle, I managed to create a program that actually works, but I ...
5
votes
2
answers
382
views
Brocard's Conjecture Candidate Finder
For fun I wanted to investigate Brocard's Conjecutre. That is, does there exist \$n, j\$ such that \$n! + 1 = j^2\$. The method I use takes inspiration from looking at divisibility rules which I ...
2
votes
0
answers
98
views
Rust implementation of a BTree
I'm studying rust, and I decided to implement a BTree as a way of learning the language.
Can anyone give me suggestions on the code?
As the language has no inheritance, and we must replace it with ...
2
votes
0
answers
143
views
Rust implementation of an algorithm I invented (RANDEVU) #2
I came up with an algorithm and created a Rust implementation of it.
I've already posted it for code review previously but created another post since I've made many changes to it, including the ones ...
5
votes
1
answer
81
views
Simple Profiler in Rust
I am writing code for a simple 'Profiler', using a struct, a hashmap, Options, and some methods. I call the profiler at many places in my code with the functions names, and the hashmap gets fed, ...
1
vote
0
answers
44
views
Collecting inputs from a list of file names or stdin if there is no input files
In my program, I want to either read from a file or stdin depending on the arguments. I did this function to collect input:
...
2
votes
1
answer
82
views
Basic rust Celsius to Fahrenheit conversion
I've been following the rust book, and I made a Celsius to Fahrenheit converter as it advised me.
After a bit, I came up with this code; however in my opinion, there's a lot of unnecessary parts that ...
1
vote
0
answers
54
views
Simple CRUD server in rust
This is my first rust application. I tried to pick somewhat low level dependencies to get a feel for the language particulars.
I'm especially interested in control flow/error patterns in rust as I ...
3
votes
0
answers
48
views
Created client server with read and write from both side
I have created client and server which can read and write from both side in client as well server. So what more improvement can be done so the code should be performant and better?
Following are three ...
4
votes
1
answer
94
views
Rust Wake-on-LAN CLI
I'm new to writing rust code, and looking for any alternate approaches to writing this code or changes to make it more idiomatic, and readable.
My use of traits, specifically, I dislike. It feels like ...
5
votes
1
answer
181
views
Sand simulation in Rust
I am working on this project to learn Rust and a bit of Web Assembly. The rendering is done in JavaScript which I do not really care about so I will not post. I would like to receive some harsh ...
0
votes
0
answers
63
views
Rust minesweeper grid generator code design
I wrote this not really to create a minesweeper game, but to practice using some of the "rusty" (but not only) design patterns and improving my code structure.
I would appreciate a review of ...
4
votes
0
answers
92
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 ...
3
votes
0
answers
170
views
ASHv2 implementation from scratch - host, transmitter and listener
I am currently implementing the EZSP and the underlying ASHv2 protocols in Rust with the intention to use them on an embedded smart home gateway to control ZigBee devices.
In this review I present you ...
4
votes
1
answer
77
views
Parsing command line arguments with CLI
I'm new to rust, and this is my very first rust program.
I'd like to write a simple CLI app to help me running some Git command on multiple repositories.
Since my goal is learning rust, I force myself ...
6
votes
3
answers
722
views
Rust: Command line menu in ASCII table
Specific areas in which I'd love to get feedback:
Is it good to have the Command struct own the Strings (...
3
votes
0
answers
84
views
Sum all numbers touching symbols in 2D grid (Advent of Code 2023 Day 3, Part 1)
Please offer suggestions to my below Rust approach for solving AoC 2023 Day 3, Part 1. The code is functionally correct, so I'm interested in understanding how I could have solved it in a more ...