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
0 votes
1 answer
38 views

Trying to find an idiomatic Rust way of calling a series of functions and early out'ing on failure of one [closed]

I would like to condense down a bunch of function calls that occur sequentially, and need to early out so they don't waste more computation later on. I've been able to get it down to the following, ...
  • 111
4 votes
1 answer
53 views

Markdown code formatter

With my rustymines 1 2 project, I realized, that it was cumbersome, to copy and paste all the code files into Markdown for review here. So I wrote a small program that formats source code files as ...
7 votes
2 answers
68 views

rustymines - a mine sweeping game with a shenanigan

I am learning Rust for about a week now. I just finished my first little working project, a mine sweeping game. The game comes with a little extra feature, namely old, broken (rusty) mines, that will ...
3 votes
1 answer
43 views

Rust language solution to old "Perl Quiz of the Week" #21

I'm particularly concerned here that I'm copying more often than I need to, and that's slowing things down; obviously, given the algorithm/approach, I need to do some copying, but I don't want to be ...
0 votes
0 answers
32 views

Euler's totient function in Rust, with a performance difference between generic and classic functions

I recently started to program in Rust, having like 2 good years of experience in C++, I thought it would be possible to directly switch to Rust without following a lot of tutorials, especially knowing ...
  • 101
1 vote
1 answer
55 views

General purpose 2D grid

I am developing (WIP) a mine sweeping game to get more familiar with Rust. I decided to represent the mine field as a 2D grid. While developing I realized that this grid can be outsourced as a general ...
2 votes
1 answer
36 views

Quadratic equation solver using ABC and PQ formula

Getting my feet wet with Rust, I implemented a solver for quadratic equations. I implemented both, ABC and PQ formula solvers, to challenge myself with branch conditions. ...
0 votes
1 answer
55 views

TCP Server using Tokio

Solving the following problem on Protohackers: https://protohackers.com/problem/1 The problem: Each request is a single line containing a JSON object, terminated by a newline character ('\n', or ...
  • 1,687
3 votes
1 answer
46 views

Simple ISO date, time and datetime implementation

I am getting started with rust. To get familiar with the language I implemented a datetime library: main.rs ...
1 vote
1 answer
51 views

Implement get_or_create() with Rust and Diesel

I just started learning Rust, and try to implement a function like Django's get_or_create. Now my implementation looks too verbose[ I hope that rust can be neater. Therefore, how can I implement this ...
  • 13
4 votes
1 answer
101 views

6502 Emulator in Rust

This is my first attempt at writing a "large program", and I think that I've got the foundations for the emulator down. However, as I'm still a beginner, I might have made some questionable ...
1 vote
1 answer
60 views

Temperature Scale Converter in Rust

Problem statement: Write a program that converts all given temperatures from a given input temperature scale to a given output temperature scale. The temperature scales to be supported are Kelvin, ...
2 votes
1 answer
106 views

Card game simulations, with a multithreaded version slower than the single-threaded one

I'm new to rust and I'm trying to build a card game simulation to find all of the best actions with all possible hands. This requires a lot of simulations and my first 3 million are already taking a ...
4 votes
1 answer
74 views

basic singly-linked list in rust

I'm new to rust and tried to implement a singly-linked list as exercise. Is this code so far suitable to solve the problem? What elements of the language should I consider to make the code more ...
4 votes
1 answer
44 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": ...
1 vote
1 answer
27 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: ...
  • 125
5 votes
1 answer
75 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 [...] ...
2 votes
1 answer
56 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 ...
4 votes
2 answers
124 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 ...
  • 434
0 votes
1 answer
36 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. <...
3 votes
1 answer
84 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 (...
  • 434
8 votes
3 answers
157 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 ...
  • 83
1 vote
1 answer
37 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 ...
2 votes
1 answer
59 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 ...
  • 133
0 votes
1 answer
63 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 ...
  • 133
1 vote
0 answers
52 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 ...
  • 343
4 votes
0 answers
37 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 ...
  • 141
3 votes
1 answer
57 views

My first rust program: transposing a CSV

Here's the result: ...
  • 131
1 vote
1 answer
45 views

get diff between two directories in rust

I'm trying to get the diff between two directories, e.g. ...
  • 111
3 votes
1 answer
51 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 ...
  • 133
3 votes
0 answers
206 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 ...
  • 31
2 votes
0 answers
92 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 ...
1 vote
1 answer
59 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 ...
2 votes
0 answers
85 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 (...
2 votes
1 answer
39 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. ...
5 votes
1 answer
105 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 ...
1 vote
1 answer
85 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 ...
  • 343
1 vote
1 answer
39 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 ...
2 votes
0 answers
21 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. ...
2 votes
1 answer
79 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. ...
  • 203
2 votes
0 answers
29 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
36 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: ...
0 votes
1 answer
56 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. ...
  • 1
1 vote
1 answer
34 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 ...
  • 207
1 vote
1 answer
49 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 ...
  • 111
2 votes
3 answers
112 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, ...
  • 121
0 votes
0 answers
22 views

Group list of objects into smallest possible number of sublists without exceeding maximum sum

I have converted my Java answer from this question into Rust. As I am new to Rust, I would like to know about what I could improve in my code. Mostly I would guess that I could improve on borrowing, ...
2 votes
0 answers
42 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 ...
4 votes
2 answers
70 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 ...
  • 163
0 votes
0 answers
35 views

I am building a container of differently typed variables with names for easy parsing and usage in Rust

I am new to Rust and trying to learn more about it. I want to have some kind of container that can store parameters (variables, values, constants) of varying types together with a name. This container ...
  • 101

1
2 3 4 5
15