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

Advent of Code 2023, Day 8 Part 1 - Beginner Rust Solution

Context I'm doing Advent of Code as a way of learning Rust, and have a working solution to Day 8, Part 1. This involves moving between nodes, starting at AAA and ...
F McA's user avatar
  • 21
4 votes
1 answer
219 views

A simple mmap(2) wrapper

I've written a wrapper for the mmap syscall. It's quite limited in functionality at the moment (there are lots of flags to support) but it's sufficient for mapping ...
haz's user avatar
  • 245
2 votes
1 answer
29 views

Using async websockets in Rust with tokio, rmp-serde and varint encoding

This is my first attempt at a real life app in Rust. I would mostly like to know if I am writing idiomatic Rust code, coming from Java and Python. I'll appreciate any pointers to improvements, though. ...
Sebastian's user avatar
  • 121
3 votes
0 answers
131 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 ...
Richard Neumann's user avatar
2 votes
0 answers
26 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 ...
Lockna's user avatar
  • 121
5 votes
1 answer
168 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 ...
roocker's user avatar
  • 51
1 vote
1 answer
44 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, ...
Elena Krittik's user avatar
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 ...
Tristan Nemoz's user avatar
3 votes
0 answers
87 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 ...
Carcigenicate's user avatar
3 votes
1 answer
56 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 ...
Tristan Nemoz's user avatar
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 ...
Richard Neumann's user avatar
3 votes
1 answer
142 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 ...
TmDobbin's user avatar
0 votes
0 answers
36 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 ...
Jake Snell's user avatar
1 vote
0 answers
61 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 (...
Niclas's user avatar
  • 21
2 votes
1 answer
91 views

Create a String from the part of the vector

I want to create a String from the part of the vector. My code: ...
mascai's user avatar
  • 397
1 vote
0 answers
39 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 ...
Richard Neumann's user avatar
5 votes
1 answer
127 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 ...
teoscuraa's user avatar
1 vote
1 answer
97 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 ...
skittish's user avatar
2 votes
1 answer
96 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 ...
byk's user avatar
  • 21
1 vote
0 answers
60 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 ...
ksjdfh's user avatar
  • 11
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: ...
ohxdMAGsDCiCJ's user avatar
2 votes
1 answer
173 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. ...
Ralender's user avatar
1 vote
1 answer
108 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 ...
Hakan Sonmez's user avatar
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 ...
Rajdeep Malakar's user avatar
2 votes
1 answer
89 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. ...
hexpev's user avatar
  • 23
2 votes
1 answer
109 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, ...
JustCarty's user avatar
  • 263
1 vote
2 answers
168 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 ...
PrancingCrabulon's user avatar
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 ...
Harry's user avatar
  • 379
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 ...
2e0byo's user avatar
  • 321
2 votes
2 answers
127 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. ...
RomainL.'s user avatar
  • 239
1 vote
0 answers
71 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 ...
PilotGuy's user avatar
4 votes
3 answers
634 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 ...
dope_centipede's user avatar
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, ...
lukstru's user avatar
  • 958
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 ...
x27ca61a's user avatar
  • 307
4 votes
2 answers
610 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 ...
Blaire's user avatar
  • 43
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: ...
Richard Neumann's user avatar
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 ...
dimo414's user avatar
  • 397
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 ...
mascai's user avatar
  • 397
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? ...
Lorenzo Salmonese's user avatar
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 ...
Tom Hosker's user avatar
6 votes
3 answers
132 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. ...
etchesketch's user avatar
1 vote
0 answers
36 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 ...
dumb_ptr's user avatar
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 ...
Tom Hosker's user avatar
1 vote
1 answer
100 views

Print Hadamard matrix of order N

Problem statement: The \$n\$-by-\$n\$ Hadamard matrix \$H(n)\$ is a boolean matrix with the remarkable property that any two rows differ in exactly \$\frac{\text{n}}{\text{2}}\$ bits. \$H(1)\$ is a \$...
x27ca61a's user avatar
  • 307
1 vote
0 answers
74 views

Recursive macro in Rust to assemble a node tree

This is my first time writing a somewhat non-trivial declarative + recursive macro in Rust. I drew inspiration from this answer. The goal is to come up with a recursive macro that allows to assemble ...
bluenote10's user avatar
2 votes
1 answer
122 views

Simulate number of children until parents have at least one of either sex

Problem statement: A couple beginning a family decides to keep having children until they have at least one of either sex. Estimate the average number of children they will have via simulation. Also ...
x27ca61a's user avatar
  • 307
3 votes
2 answers
295 views

Disprove Euler's sum-of-powers conjecture

Problem statement: In 1769 Leonhard Euler formulated a generalized version of Fermat's Last Theorem, conjecturing that at least \$n\$ \$\text{n}_{\text{th}}\$ powers are needed to obtain a sum that is ...
x27ca61a's user avatar
  • 307
4 votes
1 answer
591 views

Verifying Why Python Rust Module is Running Slow

I am working on converting some python code over to Rust, and I have come across a bit of a peculiarity in the way that my code is behaving. Namely, the module that I have written in Rust is much ...
peabody's user avatar
  • 143
2 votes
1 answer
95 views

Simulate Monty Hall

Problem statement: A contestant is presented with three doors. Behind one door is a valuable prize, behind the other two are gag gifts. After the contestant chooses a door, the host opens up one of ...
x27ca61a's user avatar
  • 307
3 votes
2 answers
144 views

Convert 9-digit integers to ISBNs

Problem statement: The International Standard Book Number (ISBN) is a 10 digit code that uniquely specifies a book. The rightmost digit is a checksum digit which can be uniquely determined from the ...
x27ca61a's user avatar
  • 307

1
2 3 4 5
17