Skip to main content

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
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: ...
genghiskhan's user avatar
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 ...
Vessel's user avatar
  • 335
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 ...
marknikky's user avatar
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 ...
Eugene Krokhalev's user avatar
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 ...
Eugene Krokhalev's user avatar
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 ...
Green grün 绿色 vert зеленый's user avatar
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 ...
Doruk's user avatar
  • 361
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: ...
Carcophan's user avatar
  • 163
-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 ...
edition's user avatar
  • 189
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. ...
Brendan Wilson's user avatar
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 ...
JayZ's user avatar
  • 109
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: <...
Vessel's user avatar
  • 335
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: ...
Dair's user avatar
  • 6,008
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 ...
Sienna's user avatar
  • 463
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 ...
flakpm's user avatar
  • 79
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 ...
Arbel Groshaus's user avatar
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 ...
Bestieboots's user avatar
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 ...
epestr's user avatar
  • 11
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 ...
roganjosh's user avatar
  • 143
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 ...
sbottingota's user avatar
  • 1,101
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 ...
flakpm's user avatar
  • 79
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 ...
zombo's user avatar
  • 43
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 ...
AashishKSahu's user avatar
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 ...
candifloss__'s user avatar
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 ...
Dave's user avatar
  • 173
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. ...
John Harrington's user avatar
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 ...
Attack68's user avatar
  • 593
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 ...
xzeck's user avatar
  • 43
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 ...
Attack68's user avatar
  • 593
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 ...
LudvigH's user avatar
  • 131
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 ...
ybjeon01's user avatar
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 ...
Dair's user avatar
  • 6,008
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 ...
rafaelgdgs's user avatar
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 ...
Eduardo Rodrigues de Farias's user avatar
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 ...
Dair's user avatar
  • 6,008
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 ...
Lucas Paixão's user avatar
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 ...
TypicalHog's user avatar
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, ...
user24615633's user avatar
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: ...
Fayeure's user avatar
  • 111
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 ...
icy icy's user avatar
  • 23
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 ...
intentionally-left-nil's user avatar
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 ...
i_am_learning's user avatar
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 ...
freebie's user avatar
  • 191
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 ...
Doruk's user avatar
  • 361
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 ...
Imaginary's user avatar
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 ...
Saphereye's user avatar
  • 233
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 ...
Richard Neumann's user avatar
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 ...
Marcus's user avatar
  • 41
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 (...
m01010011's user avatar
  • 163
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 ...
naivedeveloper's user avatar

1
2 3 4 5
18