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
191 views

First attempt using Rust, to create a simple API backing onto a JSON file

I'm trying to learn Rust, and have taken a stab at it by create a REST API, that stores the data in a local JSON file. Before I get deeper into things I'd like some feedback on if I'm doing things in ...
7 votes
2 answers
1k views

Calculating the median and mode of a list of integers

Going through the Rust book for the second time as I've been wrapped up in Typescript for a while and I want to build a personal project in Rust. In chapter 8.3, there's an exercise: Given a list of ...
3 votes
1 answer
533 views

Fast approximate sin/cos function in Rust

Over the past month or so, I’ve been trying to create an extremely fast, platform agnostic, auto-vectorizing sin/cos function for fun. I initially started with sleef-rs’s fast sin function, and ...
9 votes
2 answers
1k views

Binary adder implemented in Rust

I implemented a ripple carry adder in Rust. The function takes and outputs strings of 1s and 0s. How can I improve this ...
2 votes
1 answer
150 views

Idiomatic builder pattern in Rust

I have a couple of questions regarding how builder should be implemented idiomatically in Rust when it's necessary to call its parts depending on some flags. Here's my take on three different designs ...
2 votes
1 answer
83 views

Rust implementation of Hangman

I created a rust implementation of hangman as a command line version. The user can enter characters to find out the desired word. I really appreciate any helpful comment which highlights how I could ...
5 votes
1 answer
186 views

Data Oriented Raytracing In a Weekend in Rust

I've been learning about Data Oriented Programming, and when trying to implement this simple Raytracer, I decided to do it in this manner using Rust. This is also in the context of an optimisation ...
3 votes
1 answer
81 views

HTTP server stress tester in Rust

I wrote the following HTTP server stress tester in Rust. My actual goal was to write an efficient template for writing load testers, so I can swap out the inner loop to do e.g. requests to a Redis ...
4 votes
1 answer
140 views

Implement Seek on /dev/stdin file descriptor in Rust

Problem: In order to be able to use the arrow crate's infer_file_schema function with input piped to ...
3 votes
1 answer
111 views

RUST-based weather logger. Makes HTTP request to get a JSON and write to .csv

I've recently attempted to get into rust. I thought I would try convert my weather logging app from python to rust to maybe save some CPU cycles on my little Raspberry Pi. I have a little ESP8266 with ...
1 vote
2 answers
62 views

Implementing a function that takes in 2 collections of strings and compares them as if they are unordered in Rust

I'm new to Rust and I would like to implement a function to compare 2 collections of strings. The function should compare them as if they are unordered. In Python, I would implement something like ...
2 votes
1 answer
84 views

Smoothed Particle Hydrodynamics in Rust

So I'm simultaneously learning both Rust and Smoothed Particle Hydrodynamics. I've been using this video from AMD as a reference and the provided smoothing kernels. At this stage, I've not optimised ...
3 votes
1 answer
142 views

rust sort numbered directories (non-lexicographical)

I am very new to rust and have been reading up and playing around to get a better understanding. I was trying to replicate a small task that I have done via bash scripting before, as a way to ...
2 votes
1 answer
116 views

Rust - implementation of multiple type of graphs with shared code

I am trying to improve my Rust coding skills. One thing which I find hard to tackle is how to shift from a polymorphism you can observe in e.g. Python to sth. similar in Rust? Let me give you a ...
3 votes
1 answer
114 views

Rust Book Chapter 8 - Text interface for employee management

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 to Engineering” or “Add Amir to Sales.” Then let the ...
6 votes
2 answers
191 views

Programming Language Source Lexer

I have a lexer (program that turns source code into tokens) written in Go that I am re-writing in Rust. The lexer should take in a sequence of tokens, generally different special characters, integers, ...
4 votes
3 answers
164 views

Improving efficiency of Rust algorithm ported from Python generator

I'm learning Rust by solving ProjectEuler problems. To this end, I am trying to port a solution to problem 88 (link) in Python that heavily relies on generators to Rust (which doesn't have generators)....
4 votes
0 answers
125 views

Molecular .pdb File Reader in Rust

I am new to rust and wanted to get going with a medium-sized project to help learn. I've settled on creating some basic quantum mechanics code which starts with this bare-bones file reader. It takes a ...
4 votes
2 answers
135 views

Produce randomly-generated pronouncable names

...
13 votes
1 answer
981 views

IPv6 parsing in rust

Here is code to parse an IPv6 address. An IPv6 address is 128 bits long. When represented in its printable form, its hextets (1 hextet == 16 bits) are represented as hexadecimal numbers, and are ...
1 vote
1 answer
177 views

Text to image steganography

This simple implementation hides text secrets (S) in images by manipulating the least significant bits (lsb) on Pixels. How it works When encrypting I take a three pixel "chunk" for each ...
1 vote
1 answer
630 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 ...
3 votes
1 answer
164 views

Willans' formula in Rust

I implemented Willans' formula to calculate the nth prime number in Rust: ...
2 votes
1 answer
122 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 ...
8 votes
1 answer
869 views

Rust: Splitting a mutable slice into disjoint, but non-contiguous subslices

For some context, this is inspired by my attempt to solve this SO question. I have a mutably borrowed slice representing a 2D array, and I want to split the borrow such that I can access all the rows ...
3 votes
0 answers
313 views

Generic Monte Carlo Tree Search implementation in Rust

I'm working on a project where I need a strong AI for a combinatoric game, and decided to go with Monte Carlo Tree Search because the specific game will be original to the project - no good heuristics ...
1 vote
1 answer
157 views

Rust state-machine lexer

I tried implementing a lexer in rust that peeks ahead at the next character and makes a decision based on that. However, i am told that this is bad practice, and instead i should be using finite-state-...
0 votes
1 answer
45 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 ...
1 vote
1 answer
195 views

Finding the Median and Mode of a slice in Rust

Overview I’m trying to learn Rust, so I’m reading The Rust Programming Language. At Chapter 8, there was a task to write a program that calculates the median and mode of a bunch of numbers. I ...
0 votes
1 answer
170 views

supporting unicode in rust lexer

I am working on a lexer in rust. It has been through many different iterations, going from iterating over a Vec<char> to ...
0 votes
1 answer
121 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 ...
3 votes
1 answer
241 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 ...
1 vote
1 answer
141 views

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

So I have this binary spaced partition leaf: ...
1 vote
1 answer
98 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 ...
4 votes
1 answer
420 views

lexer for programming languages in rust

I'm relatively new to rust, so you don't need to go easy on the criticism. right now, this lexes 1MB of text (well, trims a 1MB-long word) in 30ms. is there any way I can make this faster? cursor.rs: <...
1 vote
1 answer
189 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 ...
3 votes
2 answers
267 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 ...
1 vote
1 answer
129 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 ...
34 votes
2 answers
36k views

Calculate mean, median, and mode in Rust

I'm learning Rust using The Rust Programming Language. I'm trying the assignment at the end of chapter 8 — Hash Maps. The task is: Given a list of integers, use a vector and return the mean (...
-1 votes
1 answer
125 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: ...
0 votes
1 answer
54 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 ...
3 votes
0 answers
95 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 ...
1 vote
1 answer
198 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 ...
0 votes
1 answer
107 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 ...
3 votes
3 answers
414 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 ...
2 votes
1 answer
232 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 ...
1 vote
2 answers
131 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: ...
5 votes
0 answers
936 views

A multithreaded, growable vector with immutable elements, which has wait-free reads

Disclaimer for future readers: We experimented around with a similar approach at HASH. The linked Pull Request is working. I wrote a small vector with a few lines of unsafe Rust. The idea is to have ...
1 vote
1 answer
82 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 ...
2 votes
0 answers
54 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 ...

1 2 3
4
5
18