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
25 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 ...
1 vote
1 answer
34 views

Dynamically serializing a subset of struct fields to JSON in Rust

I have a struct which, depending on options, I want to serialize to json with different subsets of the fields. However, my existing solution leads to a large amount of hard-to-maintain boilerplate. I'...
5 votes
1 answer
75 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 ...
  • 51
3 votes
1 answer
56 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 ...
  • 203
4 votes
1 answer
52 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 ...
1 vote
0 answers
73 views

Find factor pairs of an integer in Rust

I'm trying to efficiently generate all pairs of factors of a number n. For example, when n=27, the factor pairs are (1, 27), (3, 9), (9, 3), (27, 1) The order in which the pairs are found is not ...
  • 73
3 votes
1 answer
74 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 ...
  • 33
0 votes
0 answers
14 views

Smoothed Particle Hydrodynamics in Rust - Rev 2

So, I've already had this reviewed once here and having implemented the changes (save multithreading), I was wondering what people thought now. A summary of the changes: I've fixed the broken attempt ...
1 vote
2 answers
35 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 ...
  • 13
0 votes
0 answers
76 views

Vector with small internal buffer

I implemented a vector with small inline storage to avoid allocation when the size is small. I am still new to Rust, so I have no idea how good this is. I tried to match ...
1 vote
1 answer
50 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 ...
  • 203
1 vote
1 answer
50 views

DFS Maze Solver

I am new to Rust Programming so I decided to implement a Maze Solver using DFS. I was wondering if there is any way to optimize this code further ...
  • 11
2 votes
1 answer
51 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 ...
1 vote
1 answer
48 views

Quickly create polars data frame from 2D ndarray

I am sampling from m normal distributions n times each, and storing the samples in a 2-dimensional ndarray. I then need to turn this into a polars dataframe as I need to add some string columns and do ...
  • 111
2 votes
1 answer
67 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 ...
  • 123
3 votes
1 answer
63 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 ...
4 votes
3 answers
108 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)....
  • 73
6 votes
2 answers
119 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, ...
3 votes
1 answer
64 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 ...
1 vote
1 answer
108 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 ...
4 votes
2 answers
118 views

Produce randomly-generated pronouncable names

...
  • 143
0 votes
0 answers
29 views

Procedurally generated 2D grid module implemented in Rust

I've got this Rust module which implements a procedurally-generated module that operates on a 2D grid (implemented as a vector of vectors). However, I'm not sure if its idiomatic Rust or how efficient ...
6 votes
1 answer
101 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 ...
  • 163
1 vote
1 answer
73 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-...
1 vote
1 answer
55 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 ...
4 votes
0 answers
120 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 ...
0 votes
1 answer
69 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 ...
1 vote
0 answers
53 views

What do you think about this code for functions that take both pool and transaction?

I'm trying sqlx for the first time these days, sorry if this is a dumb question. I'm writing a function that I want to take both PgPool and ...
  • 193
5 votes
1 answer
114 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: <...
2 votes
1 answer
91 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 ...
2 votes
1 answer
70 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
112 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 ...
1 vote
1 answer
83 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 ...
0 votes
1 answer
63 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
2 answers
98 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 ...
  • 131
-1 votes
1 answer
69 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: ...
4 votes
0 answers
89 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 ...
  • 173
1 vote
1 answer
71 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 ...
  • 13
0 votes
1 answer
48 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
180 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 ...
  • 143
2 votes
1 answer
85 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
83 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: ...
2 votes
0 answers
38 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 ...
0 votes
1 answer
41 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 ...
2 votes
1 answer
83 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 ...
  • 373
1 vote
1 answer
54 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 ...
  • 303
3 votes
1 answer
98 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 ...
0 votes
1 answer
45 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 ...
  • 435
2 votes
1 answer
75 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 ...
1 vote
0 answers
78 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 + \...
  • 11

1
2 3 4 5
16