As of May 31, 2023, we have updated our Code of Conduct.

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
4 votes
1 answer
46 views

Zero the excess digits of an array

I wrote some code that set the last few elements of an array to zero. I call these last elements the "excess": ...
Eddie Antonio Santos's user avatar
1 vote
1 answer
32 views

Framework to create turing machines with binary increment example

I created a way to create turing machines and implemented one that increments a binary number as an example. This is the turing machine itself: ...
Cookie04's user avatar
  • 125
5 votes
1 answer
145 views

Calculate mode in Rust

I'm new to Rust and still getting used to the ownership model. I'm done with chapter 8 of the book and was trying to solve this exercise: Given a list of integers, use a vector and return the [...] ...
astral_flight_adapter's user avatar
2 votes
1 answer
123 views

Lowest Common Ancestor of a Binary Tree in Rust

I am trying to solve the lowest common ancestor problem in Rust. It is guaranteed that the id's of the tree are unique. It is also guaranteed that the two nodes which we are looking for in the tree ...
Agnishom Chattopadhyay's user avatar
4 votes
2 answers
157 views

Project Euler #51: "Prime digit replacements" in Rust

Problem: https://projecteuler.net/problem=51 "Find the smallest prime which, by replacing part of the number (not necessarily adjacent digits) with the same digit, is part of an eight prime ...
sarema's user avatar
  • 449
0 votes
1 answer
38 views

rust: Set configs from env and reuse it during app's lifetime [closed]

After writing a basic API with rocket, I'm trying to improve it, but I'm not sure how to follow up. Each time a new request comes in, the code keeps looking for the variable from the environment. <...
Patrick Marangone's user avatar
3 votes
1 answer
89 views

rust: idiomatic use of generics when using a filetype-dependent writer

Simplified from https://github.com/132nd-vWing/tacview-splitter. External dependencies: zip crate The code would do the following: read a file from disk (...
sarema's user avatar
  • 449
8 votes
3 answers
226 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
1 vote
1 answer
40 views

App for grabbing data from some APIs (electricity usage & solar panel production) & putting them into a DB

I made an app for my internal use that collects some metrics & puts them into a DB. I'd be happy if someone could comment on my code, commenting, design choices and so. I hope I did enough ...
Timotej Leginus's user avatar
2 votes
1 answer
90 views

Rust book: Employees and departments exercise

I am learning Rust from the official book, and I have solved the following recommended challenge from the end of chapter 8: Using a hash map and vectors, create a text interface to allow a user to ...
lorinet3's user avatar
  • 133
0 votes
1 answer
141 views

Rust Pig Latin exercise solution

I just finished the chapter about collections from the Rust book, and it recommended trying some exercises provided there, such as a Pig Latin translator. Convert strings to pig latin. The first ...
lorinet3's user avatar
  • 133
1 vote
0 answers
111 views

Simple rust ECS with no dynamic dispatch

I'm trying to write a minimal, high performance uncomplicated ECS for a simple game in which I have a good idea of all of the Entity and Component types from the get-go. I want to take advantage of ...
Blue7's user avatar
  • 373
4 votes
0 answers
82 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 ...
Arshia001's user avatar
  • 141
3 votes
1 answer
106 views

My first rust program: transposing a CSV

Here's the result: ...
HolKann's user avatar
  • 131
1 vote
1 answer
118 views

get diff between two directories in rust

I'm trying to get the diff between two directories, e.g. ...
Lucas's user avatar
  • 111
3 votes
1 answer
68 views

Radial gradient image generator

A function to create a radial gradient from one rgb colour to another and using rayon to improve performance. Are there better way to convert between some of the types / any obvious performance ...
Jacob's user avatar
  • 133
3 votes
0 answers
742 views

Efficiency of wgpu-based 2D Batch Renderer

I've been working on a WebGPU-backed Rust renderer that batches together 2D colored sprites. I hadn't gotten onto the "sprite" portion of it yet, but I'm already finding some performance ...
n77's user avatar
  • 31
2 votes
0 answers
226 views

Cosine similarity calculation in Rust, which is slower than NumPy

I'm running this in release mode. Currently, the following function takes around 6.7 seconds to run on my computer vs 3.7 seconds on Python. I know that Numpy is just calling to C, but I'm trying to ...
Karl Hernandez's user avatar
1 vote
1 answer
65 views

Optimal Jelly string compressor in Rust

I'm writing some small programs to practice Rust, and this one's a string compressor for the golfing language Jelly (unofficial spec). It involves some non-ASCII stuff and bigints (from the ...
Radvylf Programs's user avatar
2 votes
0 answers
319 views

Rust code implementing cosine similarity

I've been trying to create a piece of code which consists of looping through each element of a list of questions, preprocess it, and then calculate the Cosine similarity with the rest of the elements (...
Shodai Thox's user avatar
2 votes
1 answer
86 views

Implementing Ord trait for an Iterator Wrapper

Recently, I needed to sort iterators by their first value and/or use them in BinaryHeap. There are things I don't like about this implementation: Using RefCell. ...
night-crawler's user avatar
5 votes
1 answer
272 views

Filtering an Option Result using a boolean Result in Rust

I'm trying to rewrite one of my pet projects in Rust, and when I was faced with the problem of filtering a Result<Option<T>, E> via a ...
Yalin Gunayer's user avatar
1 vote
1 answer
303 views

Multithreaded observer pattern in Rust

I often want to program in an event driven way, but classic implementations of the observer pattern often pose an ownership challenge, and they only get more difficult once multiple threads are ...
Blue7's user avatar
  • 373
1 vote
1 answer
68 views

Lexer for shell-like language [rust]

I am working on writing a rust implementation of a sh-like language. Rather than posting 600 lines of code here, you can just go to the GitHub repository. Is this a ...
CATboardBETA's user avatar
2 votes
0 answers
71 views

Rust Undertale Save File Loader

This code's job is to load save files from a subfolder in ~/undertale-saves and save them to ~/.config/UNDERTALE_linux_steamver. ...
Tornado547's user avatar
2 votes
1 answer
268 views

A database trait in Rust. How can I make all these generic parameters easier to use?

I am trying to hide the implementation details of accessing a Postgres database. To do this, I want to create "database" and "transaction" traits for use in a repository struct. ...
haz's user avatar
  • 203
2 votes
0 answers
48 views

Get ffmpeg command to encode video in x265 codec and downscale to `max_height` resolution

I'm translating the python program video-diet as I am learning rust. The program is to recursively compress video files in a directory, but here I'm just preparing ...
user avatar
0 votes
1 answer
83 views

Rust vector iteration and integer conversions

Started learning Rust by solving LeetCode problems as they involve all the standard data structures of the language. I have the following standard hash table solution to the two-sum problem: ...
Edvard Fagerholm's user avatar
0 votes
1 answer
78 views

Rust: Unsecure Static Once

I am basically a beginner, so I Wrote some code that implements a zero cost singleton, through it will crash your program if you have a MMU. ...
Delfin's user avatar
  • 1
1 vote
1 answer
35 views

Rust program to print citations in Chicago author-date style

I have written a Rust program that lets you input a citation's metadata in a Bibtex-like format and generates a bibliography entry formatted in Markdown that conforms (more or less) to the Chicago ...
Max's user avatar
  • 207
1 vote
1 answer
73 views

Unit tests for PNGme steganography exercise in Rust

I want to become proficient in Rust and I've followed the PNGme exercise. I've completed it up until Chapter 4 included, where I've written a lot of tests myself for verifying that the command line ...
rdxdkr's user avatar
  • 111
2 votes
3 answers
125 views

Calculating square roots using binary search

I'm trying to find the square root of a number (num) using binary search in Rust. I'm new to Rust, but I've done quite a bit of programming in other languages, ...
cocomac's user avatar
  • 123
2 votes
0 answers
44 views

Algorithm for solving `subsequence with highest win rate`

Problem Inputs: 1. min length of subsequence 2. binary sequence outputs: 1. starting index of sequence 2. subsequence length The task is to find a subsequence ...
Hamza Zubair's user avatar
4 votes
2 answers
169 views

Cleanly modifying values in hashmap for a k-sum challenge

Just started learning Rust and here's a program that has caused me some agony to implement in Rust. This is very easy to implement in C++, but Rust's borrow checker is causing all sorts of trouble. My ...
eof's user avatar
  • 193
1 vote
1 answer
37 views

Sensibly using fastq crate to modify fastq files

I'm learning Rust, and I have a simple program that I hope to use as a learning exercise. My goal here is to get a better idea of the proper way of doing things. I'm trying to use the fastq crate to ...
Tsaari's user avatar
  • 11
2 votes
2 answers
134 views

Partitioning a list so that even numbers appear before odd numbers

I started learning Rust today and figured, I could ask for some code reviews to learn to make my code idiomatic and learn about its code generation. I spend my days writing highly optimized Java and C+...
eof's user avatar
  • 193
1 vote
2 answers
64 views

Generate vertices and normals for a flat shaded cylinder

I would like to generate list of vertices and normals (with the correct indices) for rendering a cylinder barrel (I ommited the end caps for brevity). The normals should not be interpolated (flat ...
frankenapps's user avatar
3 votes
2 answers
227 views

Extremely simple virtual machine in Rust

I wrote a very simple VM to get a bit more familiar with Rust. The VM architecture was not the focus, so that I think that can safely ignored. Is my code idiomatic and clean? I felt that I was very ...
xilpex's user avatar
  • 289
6 votes
1 answer
88 views

Tic Tac Toe Module in Rust: Implementing "new"

Intro In order to get familiar with and improve my Rust skills I coded Tic-Tac-Toe. I want to write good Rust code, any feedback regarding why my code isn't in a Rust style or improvements that could ...
itsderek's user avatar
8 votes
2 answers
850 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
1 vote
0 answers
25 views

Wrap an ssh2 connection neatly and pass commands

I want to structure this better but don't think I'm handling results well. I'm used to python and I think my flow is way off. Is this bad design? Should my results be Result<String, Error>? I'm ...
shaciaran's user avatar
1 vote
1 answer
141 views

The Rust Programming Language book: Company HashMap exercise (Ch. 8)

This is my solution to the third exercise (and last) at the end of chapter 8 of The Rust Programming Language book (https://doc.rust-lang.org/book/ch08-03-hash-maps.html#summary). There are only 3 ...
spketre's user avatar
  • 11
3 votes
0 answers
90 views

Rust book chapter 8.03- Text interface to add employees

https://doc.rust-lang.org/book/ch08-03-hash-maps.html Using a hash map and vectors, create a text interface to allow a user to add employee names to a department in a company. For example, “Add Sally ...
Lewis Farnworth's user avatar
1 vote
0 answers
694 views

Rust: nested values within struct

I want to understand how to properly nest key/pair values within a struct. My use case is to create a type to return serialized JSON on my API responses. I'm using rocket, this is my general setup: <...
Emille C.'s user avatar
  • 111
1 vote
0 answers
168 views

Console Tic-Tac-Toe game in Rust

While having experience with other languages I only recently started learning Rust and I was hoping to get some feedback on my little beginner project, especially regarding style (stuff like too many ...
D4v1d 247's user avatar
2 votes
0 answers
44 views

Reverse Words in a String, while preserving the order of words - rustlang

Source: https://leetcode.com/problems/reverse-words-in-a-string-iii/ I want to know What better could I do, regarding syntax and idioms What better could I do, regarding performance ...
delete me's user avatar
2 votes
1 answer
90 views

A Rust beginner's Hangman game

I have been learning Rust for a few days (This is my third) now, and I've really fallen in love with the language, this is my first real project, Hangman. I was wondering what I could do better / what ...
Sam's user avatar
  • 43
6 votes
0 answers
77 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 ...
lml's user avatar
  • 61
2 votes
0 answers
92 views

Mastermind in Rust

To learn Rust I coded a clone of Mastermind. Mastermind is a 2-player game, where a master chooses a combination of 4 pegs which are of 6 different colors (For example : Red Yellow Blue Red) The other ...
ElevenJune's user avatar
1 vote
1 answer
119 views

Continuous knapsack problem in Rust

Background The continuous knapsack problem is the following linear program: $$ \begin{align} \text{maximize} \quad & f(x) = \sum_{i=1}^n u_i x_i \\ \text{subject to} \quad & \...
Max's user avatar
  • 207

1 2
3
4 5
16