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
2 votes
1 answer
32 views

Create bash ranges from integer sequences

The following code is meant to generate ranges from arbitrary integer sequences and print them in a bash-like syntax: main.rs ...
5 votes
1 answer
92 views

Learning rust by writing a calculator

As the title suggests, I'm learning rust. My go to starter project when learning a language is to write a calculator. It's relatively simple, but complex enough that you will need to utilize many ...
2 votes
1 answer
59 views

Prime sieve in Rust

Using Sieve of Eratosthenes, I created a function that returns a vector of primes up to given limit. ...
0 votes
1 answer
53 views

thread creation and termination design pattern in rust

I am new to rust and come from a Java background. Currently I'm trying to imitate the java methodology of thread creation using ...
4 votes
1 answer
143 views

Fahrenheit <=> Celsius converter in Rust

It's one of the tasks suggested in the Rust Programming Language book by Steve Klabnik and Carol Nichols, and to a complete Rust newbie like me, figuring out converting scale from ...
2 votes
1 answer
61 views

Parallelization of the tick function in a Game of Life simulation using Rust and Python (+ NumPy)

I've been writing a small Rust module recently with the sole purpose of speeding up my Python program, which is a Conway's Game of Life simulation. The function written in Rust is called from Python ...
4 votes
1 answer
63 views

C# wrapper that binds to Rust FFI, for the purpose of running CavalierContours functions in Unity

I have attempted to write c# bindings for a Rust library. I have never worked with unmanned code / languages before. Superficially this code does work with no apparent bugs or memory leaks. I want to ...
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 ...
1 vote
1 answer
82 views

Complex numbers implementation in Rust

I am learning object oriented programming in Rust. I created my own struct for complex numbers. Could you please review and answer my questions: Is it possible to implement C++-like default ...
3 votes
1 answer
55 views

End to End testing of user interaction in Rust

I am interested in any kind of possible improvement to this method of testing a Rust program with user interaction in an end-to-end manner (simulating user input and asserting a certain program output ...
3 votes
1 answer
72 views

Deciding between rust-specific and conventional syntax

I am learning Rust by implementing a series of simple modules which I tend to use a lot in other languages. One of them describes simple methods done on intervals (union, intersection, etc). Here I ...
2 votes
2 answers
101 views

Rust: Looping over every file in a directory, collecting and modifying filenames and metadata

I'm building a simple blog with Axum and Rust, mainly to practice Rust. I find myself finding working solutions to the things I want to do, but I don't like the end result of my code, it doesn't feel ...
1 vote
2 answers
78 views

Sort by parity in rust

I am learning sorting in rust. I want to sort vector as such that even numbers go first My code is OK. But can it be improved (I want to use sort function)? ...
0 votes
2 answers
57 views

Checking which programs are used for scripting

I have a directory where there are some script files, some binary files, and some subdirectories. I have tried to write a program which gets names of all files in directory, and excludes if they are ...
5 votes
3 answers
610 views

Merge Sorted Array in Rust

I was solving this task https://leetcode.com/explore/learn/card/fun-with-arrays/525/inserting-items-into-an-array/3253/ The main idea is to merge two sorted arrays (more details in the site) Example: <...
5 votes
1 answer
60 views

Checking if a graph is fully connected

After reading the rust book for some time I decided to create my first program which implements a graph. There are a few things I was wondering about, such as if the file structure is appropriate (the ...
3 votes
0 answers
147 views

Tauri/Rust small program to upload files with use of threads and openssh

First time I'm using Rust in one of my programs and I feel a lot can be improved. I don't have any colleagues / friends that already used Rust so this is the only way to get some validation that it's ...
1 vote
1 answer
65 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'...
4 votes
1 answer
86 views

Find the longest palindromic subsequence - Using a hashmap in Rust

This is a leetcode question which I wanted to solve using Rust as I'm learning Rust at the moment. I would appreciate some feedback on how to write it idiomatically. Link to the question: https://...
7 votes
1 answer
316 views

piglatin exercise in rust

This is my attempt to make the exercise suggested at the end of this chapter of rust's official tutorial ...
2 votes
1 answer
69 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 ...
3 votes
1 answer
107 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 ...
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
168 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
945 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
77 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 ...
1 vote
1 answer
80 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 ...
2 votes
1 answer
64 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
103 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 ...
5 votes
1 answer
113 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
63 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
65 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
83 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
47 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 ...
0 votes
0 answers
18 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 ...
0 votes
0 answers
80 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 ...
2 votes
1 answer
55 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
66 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
73 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
68 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
128 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
119 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
115 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
121 views

Produce randomly-generated pronouncable names

...
13 votes
1 answer
795 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
117 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
352 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
113 views

Willans' formula in Rust

I implemented Willans' formula to calculate the nth prime number in Rust: ...
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 ...
6 votes
1 answer
179 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 ...

1
2 3 4 5
16