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
3 votes
0 answers
71 views

Parse two-digit numbers from text

I am participating in this year's Advent of Code for fun. Challenge 1.2 states: The newly-improved calibration document consists of lines of text; each line originally contained a specific ...
2 votes
0 answers
20 views

Ringbuffer over a const generic Array in Rust

I implemented this generic ringbuffer over a const generic array with the usage of the MaybeUninit type. Is there something which is maybe unsound (having the lines ...
5 votes
1 answer
151 views

My attempt at GNU echo in rust

This is my first post. I'm trying to learn Rust and I recently finished reading the Rust Book. For further learning I decided to try to reimplement some GNU core utilities in Rust. This is my approach ...
1 vote
1 answer
39 views

Idiomatic way to filter a `Vec` of version identifiers to only include latest version for each minor release?

I have a Vec<String> of all available versions of a particular piece of software (Godot), named VERSIONS in code below, ...
2 votes
0 answers
29 views

Assign unique identifiers to binary matrices using a binary tree

Context I want to build a transposition table where the game states are binary square matrices which size MATRIX_SIZE is known at compile time. Rather than storing ...
3 votes
0 answers
86 views

Mandelbrot Set image generator in Rust

I'm learning Rust, and as-is tradition, I'm starting out with a Mandelbrot Set explorer as my first project (although, it just produces images so far). When run, it just creates and writes an image to ...
1 vote
1 answer
344 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 ...
3 votes
1 answer
140 views

Get HTTP status of many URLs

I'm brand new to using rust, so please bear with me. I'm trying to write a rust program which takes two arguments: A URL, and a wordlist. This wordlist has the following contents, and is several ...
3 votes
1 answer
54 views

Hashing a fixed size binary stream with a tree structure in Rust

For a research project, I want to assign a unique identifier to a stream of bits. I can assume that all the streams will always have the same size. Because of this nice property, my idea has been to ...
4 votes
0 answers
21 views

Procedural macro to derive de/serialization trait from/to little endian bytes

I wrote a trait library that allows the de-/serialization of data structures from/to little endian bytes 1. For it I now wrote my first procedural macro 2 to be able to derive the traits ...
1 vote
1 answer
137 views

Efficient Connection Pooling in ODBC-MSSQL with Rust (odbc-api)?

I want to connect to MSSQL using ODBC (odbc-api) at the beginning of my server application created with hyper.rs. I want to have a connection pool and obtain a connection within each request, which ...
0 votes
0 answers
35 views

Mac M1 .BF Compiler in Rust

I'm writing a brainfuck compiler in rust, that takes brainfuck instructions and converts them to a very basic assembly form, and then compiles that into binary, if you are not familiar with brainfuck ...
1 vote
0 answers
60 views

Buddy - Algorithm in Rust

I wrote my first code in Rust and decided to recall the buddy algorithm, which I suggested at work for our embedded software. I hope you can give me some advise on things like: How to make it safe (...
2 votes
1 answer
90 views

Create a String from the part of the vector

I want to create a String from the part of the vector. My code: ...
5 votes
1 answer
126 views

Recreated Snake in Rust

This is my first ever program in Rust. I've made it using only the book, the reference, and any documentation about the crates/functions I was using on the official rust lang website. I have the ...
1 vote
0 answers
37 views

Trait to extend std::io::Read and std::io::Write

While implementing a proprietary networking protocol, I found myself instantiating buffers of different sizes all the time, reading from a std::io::Reader into it ...
4 votes
1 answer
1k 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 ...
1 vote
1 answer
96 views

Leetcode: Maximum score from performing multiplication operations

I am looking for feedback on how to make my code more performant (take less time) - specifically with a top-down approach. My specific asks are: How can I make this code faster? It currently takes ...
2 votes
2 answers
125 views

implementing a min/max Heap in rust

I am more on data analyst than a programmer, but I do enjoy coding for fun. I tried to implement a Heap in rust. I would appreciate any return you may have, so I can improve. ...
2 votes
1 answer
94 views

minitalk project using Rust | Communication between process using UNIX Signals

I am trying to build minitalk project from 42 school using Rust instead of C. This is a communication program between a client and a server. Both are process. To achieve this I am only allowed to use ...
1 vote
0 answers
57 views

Rust rocket file upload endpoint

I'm currently learning rust and need a rocket file upload enpoint for a project. This is what i currently have: It needs to get the file, convert it and add a entry with the file name and timestamp to ...
2 votes
1 answer
172 views

Rust implementation of fibers

I am still new to rust, so any comment about what is the rust way of doing things is welcome. this is a hand-rolled implementation of fibers or user-land context-switching. ...
0 votes
0 answers
30 views

Executing a Method Twice Concurrently for the Same Object

Q1: considering the code below: Is there something wrong with this approach where the protocol object is shared between peers, and each peer runs the object's run method and keep it running? Q2: ...
1 vote
1 answer
104 views

A simple parser for bencoding format

I have been learning rust sporadically for a while now and decided to write some toy projects. While browsing https://github.com/codecrafters-io/build-your-own-x I came across some bittorrent client ...
4 votes
1 answer
93 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 ...
4 votes
1 answer
46 views

ShareImage: Place Texts on Images to generate Social Media Preview Images

ShareImage is a project which lets you use an Image ("Template") and place text over it, to generate Social Media Preview Images, the ones used in the ...
2 votes
1 answer
116 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 ...
2 votes
1 answer
88 views

Project Euler Problem 1: Multiples of 3 or 5

The following is my solution to Project Euler Problem 1: Multiples of 3 or 5. ...
2 votes
1 answer
105 views

Simple Rust Todo List with auto incrementing ID

I have recently started learning Rust and thought I'd start out with the classic Todo List application. The application simply loops forever asking the user to type a number to do specific actions, ...
1 vote
2 answers
164 views

Two sum sliding window challenge

The task is a simple coding challenge I took part in. It is a spin on the two sum problem. In the two sum problem you are given an validation sequence A and a test input I. I is valid if it's the sum ...
3 votes
1 answer
101 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
76 views

Rust Network Interface

I have written code related to network communication interface which basically has functionalities of create socket and send & receive data. Currently this supports only IPV4 but facing lot of ...
0 votes
0 answers
75 views

beep-evdev - Beep the PC speaker on Linux using evdev

Updated question on 2023-08-31 with extended codebase, since so answers were posted yet. Background I am rewriting a program in Rust, which needs to be able to beep the PC speaker. I am using a udev ...
1 vote
0 answers
48 views

Debounced inotify watcher in rust

Here is a tiny (cli) tool to run a script with the state of any of a set of watched files when one of them is opened or closed. It applies basic debouncing to handle bursty access. It was written to ...
5 votes
1 answer
227 views

Largest Prime factor (Project Euler in Rust)

I've been working on my Rust a bit and want to know how idiomatic my rust code is for the following Project Euler problem: ...
0 votes
1 answer
41 views

Function returning a vec with prime factors of number

See code below and my comment with questions: ...
3 votes
1 answer
145 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 ...
1 vote
0 answers
66 views

Optimizing tokio and pcap Operations in Rust for Max Throughput

Background I'm mostly a c# and python programmer and am slowly learning Rust. I'm not sure if that is contributing to incorrect concepts as to how threading and io work in Rust, but that's what I'm ...
1 vote
2 answers
78 views

Update JSON object in outer object or insert a default one

The below code is part of a program that, among other things, configures a Chromium profile: ...
4 votes
3 answers
632 views

What might be the best way to rewrite this in idiomatic Rust?

Below is a simple Rust program which inter-converts temperature between the Celsius scale and the Fahrenheit scale. It takes two inputs: scale referring to the temperature scale of the next input the ...
6 votes
2 answers
1k views

Another pig latinize rust implementation

Yes, I know this exercise has been posted before, but I'm posting it again because I want feedback on why certain parts of my code aren't idiomatic. I'm new to rust, and my code works, but as I said, ...
3 votes
1 answer
84 views

Simulate M random walkers N times and visualize relationship between walker number and grid size

Problem statement: Suppose that n random walkers, starting in the center of an n-by-n grid, move one step at a time, choosing to go left, right, up, or down with equal probability at each step. Write ...
4 votes
2 answers
609 views

Rust Elo rating

I have just started learning Rust and wanted some feedback on a simple program for calculating Elo ratings. All of the following code was in a single file, but I imagine that this is the part that ...
1 vote
0 answers
36 views

Handling a subprocess' output in background threads and accepting user-provided sinks for the output

I have a PR swapping from Command::output() to a custom implementation using threads to handle the subprocess' stdout/stderr while the program is running, instead ...
1 vote
1 answer
72 views

URL healthcheck script

Task: develop a CLI utility for HTTP Health check at a given URL. The check is performed in a cycle with a specified interval. On each iteration of the HTTP GET activity on the given URL. There are ...
0 votes
0 answers
69 views

Tried to come up with a novel sorting algorithm on my own

As said in the title, I tried to come up with a sorting algorithm on my own to practice. It seems to work, even though it's not in place. Is it "new" or does it already exist? ...
1 vote
1 answer
63 views

Flowers in the Window: An Exercise in Using Classes and Objects in Rust

The Problem As part of my doomed efforts to learn Rust, I decided to get to grips with how the language handles classes and objects. But, instead of taking on some well-known exercise, I thought it ...
6 votes
3 answers
131 views

Idiomatic and performant file hashing

I've written a small program that will accept a directory path and recursively calculate the MD5 hash of each file. ...
1 vote
0 answers
35 views

I'm writing the command processing part of the tui for a basic task manager/todo list application

The idea is that the TUI struct handles what gets printed to the terminal (I will make it pretty in the future, right now I'm just building its core functionalities) and for processing input. It's ...
3 votes
1 answer
144 views

Hunting for the 100,001st prime in Rust

Most of my programming experience is in Python, but my first language was C, and I was intrigued by the combination which Rust offers: a streamlined syntax and no manual memory management, but with ...

1
2 3 4 5
17