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
1 vote
1 answer
92 views

'Learning' Animal Guesser Program

I've written a program that uses a binary tree to essentially 'learn' about animals given the name and questions about them. Learn is probably a little strong of a word, all it does is store the ...
ravenclaw900's user avatar
1 vote
1 answer
81 views

Binary space partition implemented in Rust which operates on a 2D vector

So I have this binary spaced partition leaf: ...
Aspect11's user avatar
1 vote
1 answer
128 views

The Twelve Days of Christmas

I'm trying to learn Rust and for this reason I'm reading the Rust Book. It contains the following exercise: Print the lyrics to the Christmas carol “The Twelve Days of Christmas,” taking advantage of ...
DisplayName's user avatar
1 vote
1 answer
95 views

Fibonacci calculator

I'm trying to learn Rust and for this reason I'm reading the Rust Book. It contains the following exercise: Generate the nth Fibonacci number. Here's my take. Note I'm only using material from ...
DisplayName's user avatar
0 votes
1 answer
77 views

Celsius Fahrenheit converter

I'm trying to learn Rust and for this reason I'm reading the Rust Book. It contains the following exercise: Convert temperatures between Fahrenheit and Celsius. Here's my take. Note I'm only using ...
DisplayName's user avatar
3 votes
2 answers
106 views

Forward TCP packets from one connection to another

I am new to Rust but well versed in Go. I have written the following program which initiates connection to the remote-addr and starting a thread to listen to the ...
Nick's user avatar
  • 131
-1 votes
1 answer
76 views

top-down lexer in rust

the other day, i decided to build a top-down lexer in rust, just for fun. this is what i have so far: ...
John doe's user avatar
3 votes
0 answers
91 views

AoC Day 8 2022 - Pola-rs Dataframes

Description of the problem and the input data is here https://adventofcode.com/2022/day/8. The algorithm is essentially: Find the cumulative max value in a given direction and shift by 1 Find the ...
db579's user avatar
  • 163
1 vote
1 answer
123 views

Deserializing JSON data with flexible key and type into structures

I need to parse JSON data that's got a... unique structure. It either looks like this: {"ok": true, "<key>": .... } or this ...
pkce's user avatar
  • 13
0 votes
1 answer
59 views

Extend iterators with until() function

I want to extend generic iterators with a convenience function until() that works like an inversion of take_while(). Here is the ...
Richard Neumann's user avatar
3 votes
3 answers
225 views

Tree implementation in Rust

I am a beginner to Rust, started learning because of Advent of Code 2022. I solved Day 7's problem by implementing a tree data structure and traversing it. TLDR, the problem provides a log of terminal ...
Gareth Ma's user avatar
  • 143
2 votes
1 answer
113 views

Modelling mathematical expressions in Rust

I've been trying so hard to come up with a data model that works for mathematical expressions (like x^2 + 2x - y * 4, no equals sign) in Rust. It's very different to other languages I'm most familiar ...
theonlygusti's user avatar
1 vote
2 answers
90 views

Idiomatic Rust API to X11 displays

I am currently implementing a native Rust API to X11, especially around the XDisplay for a related project. I chose an object-oriented approach: ...
Richard Neumann's user avatar
2 votes
0 answers
41 views

Program to hide the cursor on a running X.org server

I have a use case where I need to programmatically hide the cursor on a running X.org server. While the suggested C progam works, I wanted to learn a bit about the X.org API and get some practice with ...
Richard Neumann's user avatar
0 votes
1 answer
42 views

ANSI background color codec

After a discussion of a mysterious color code on the Arch Linux live medium on the Arch Linux forums, I implemented a codec to encode (and decode) arbitrary byte streams to ANSI background colors. The ...
Richard Neumann's user avatar
2 votes
1 answer
97 views

A Spatial Hash View: Store references to spatial data so it can be used for performant broad phase collision detection

I have created a non-owning view of some spatial data that organises the data into cells. The data is split into a grid of cell size 100, and the key to the ...
Blue7's user avatar
  • 373
1 vote
1 answer
59 views

State machine for parsing GitHub URL formats

A while ago, I wrote a small Rust crate for parsing & generating URLs for GitHub repositories in various formats (HTTPS, SSH, git://, etc.), with the parsing done using regular expressions with ...
jwodder's user avatar
  • 303
3 votes
1 answer
122 views

Calculate median and mode in Rust

I am reading the Rust book. I am on chapter 8; this is the assignment: Given a list of integers, use a vector and return the median (when sorted, the value in the middle position) and mode (the value ...
Muhammad Najib 's user avatar
0 votes
1 answer
48 views

Protein Translation Learning Exercise from exercism.org

I'm learning Rust by solving exercises from different tracks on Exercism. The below code is an implementation of "Protein Translation" from the Python track. I split ...
Saurabh's user avatar
  • 435
2 votes
1 answer
80 views

Linked list in rust, Needed optimization

I've implemented constructor, push , pop, drop and some macro. I need to know if the drop implementation is correct and is drop is really necessary? Meanwhile I still didn't check about ...
Nithin Gowda's user avatar
1 vote
0 answers
97 views

Geometric Brownian Motion Monte Carlo simulation in Rust

I am going through code that I wrote a while ago in Rust that simulates Geometric Brownian Motion. Geometric Brownian Motion satisfies the stochastic differential equation: $$dS_t = \mu S_t dt + \...
FISR's user avatar
  • 11
2 votes
1 answer
95 views

Multithreaded segmented Sieve of Eratosthenes

I am fairly new to Rust and thought a good way to practice would be to write a multithreaded segmented Sieve of Eratosthenes. It performs ok (searches ten-billion numbers in about 11 seconds on my ...
knots427's user avatar
1 vote
1 answer
64 views

implement `getcwd(3)` in Rust

I am trying to implement a getcwd(3) (or env::current_dir() in Rust std). In the implementation, I use a ...
Steve Lau's user avatar
  • 113
2 votes
1 answer
123 views

Middle of the Linked List in Rust

Yesterday, inspired by some great questions here, I decided to give myself some practice with Rust, by solving all the introductory questions over on LeetCode. It was a great learning exercise, and ...
Davislor's user avatar
  • 4,440
2 votes
1 answer
128 views

2021 Day 1 Advent of Code in Rust

I'm preparing for the Advent of Code 2022, and in order to shake off the cobwebs, I'm attempting some problems from the previous year in rust. Starting at Day 1, I've been trying to get comfortable ...
C.Nivs's user avatar
  • 2,502
3 votes
1 answer
77 views

Number to Roman in Rust

I solved LC12 (Integer to Roman) in Rust. I am a beginner with Rust, so I translated my previous solution from C++ to Rust. I am looking for feedback on how I could improve the following Rust code. ...
Mircea's user avatar
  • 300
0 votes
0 answers
49 views

Parsing log files for scan date, IP address, ports, etc. to create JSON

I wrote this code that uses the nom library to parse some values from a log file and then output data in JSON format. I had to use a lot of variables for the cases when the parses found nothing, ...
Erty Desu's user avatar
2 votes
1 answer
74 views

Calculating median value from a list of numbers

I am learning Rust and I would like to get some feedback around my solution to calculate the median value from a list of integers. I believe the logic is correct as my tests pass, but I'm concerned ...
Guillaume Renoult's user avatar
3 votes
1 answer
113 views

Willans' formula in Rust

I implemented Willans' formula to calculate the nth prime number in Rust: ...
Richard Neumann's user avatar
1 vote
2 answers
67 views

Collect gaps in a number sequence in Rust using Vec::windows

I have the following code which collects gaps in a number sequence into a separate vec. There will never be a case, iterating over a ...
Nic's user avatar
  • 201
4 votes
1 answer
126 views

Creating an image of the Mandelbrot set in Rust

I'm in the process of familiarizing myself with Rust. In order to get some practice, I decided to make a program that generates images of the Mandelbrot set. The function I use to generate the image ...
Colin's user avatar
  • 107
4 votes
1 answer
100 views

Approximate concurrent counter in Rust

I am reading chapter 29 of OS: the three easy pieces, which is about concurrent data structures. The first example these is an approximate counter. This data structure increments numbers by using a ...
ybjeon01's user avatar
4 votes
1 answer
228 views

Runge-Kutta 4 implementation in Rust

This is a toy problem. I want to try using Rust for numerical modeling, but I found zero tutorials for this kind of stuff. I also just started learning Rust yesterday, so please bear with me. Usually ...
Yuriy S's user avatar
  • 205
1 vote
1 answer
346 views

Rust - Hexadecimal to Base64 conversion (Cryptopals challenge 1)

Here's my solution to the first challenge of the Cryptopals Crypto Challanges (https://cryptopals.com/sets/1/challenges/1). I decided to use a cargo workspace to structure my project with the library ...
glimapt's user avatar
  • 11
3 votes
0 answers
28 views

Unsafe Rust FFI code to access Razer products on macOS

I am new to Rust and specially new to FFI programming, and I am porting a macOS specific C library called librazermacos to Rust. While writing some public APIs I came up with my first two methods ...
kolrie's user avatar
  • 131
0 votes
1 answer
73 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, ...
Water's user avatar
  • 111
4 votes
1 answer
78 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 ...
Richard Neumann's user avatar
7 votes
2 answers
89 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 ...
Richard Neumann's user avatar
3 votes
1 answer
65 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 ...
Daniel Martin's user avatar
0 votes
0 answers
49 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 ...
Teyzer18's user avatar
  • 101
1 vote
1 answer
69 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 ...
Richard Neumann's user avatar
2 votes
1 answer
56 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. ...
Richard Neumann's user avatar
0 votes
1 answer
610 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 ...
Rish's user avatar
  • 1,689
3 votes
1 answer
66 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 ...
Richard Neumann's user avatar
1 vote
1 answer
96 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 ...
Aleksey's user avatar
  • 13
4 votes
1 answer
191 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 ...
Leon9343's user avatar
1 vote
1 answer
71 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, ...
Christian Hujer's user avatar
2 votes
1 answer
139 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 ...
PaulEliaz's user avatar
5 votes
1 answer
112 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 ...
panda_snail's user avatar
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
2
3 4 5
16