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.
867
questions
2
votes
1
answer
39
views
Basic rust Celsius to Fahrenheit conversion
I've been following the rust book, and I made a Celsius to Fahrenheit converter as it advised me.
After a bit, I came up with this code; however in my opinion, there's a lot of unnecessary parts that ...
1
vote
0
answers
31
views
Simple CRUD server in rust
This is my first rust application. I tried to pick somewhat low level dependencies to get a feel for the language particulars.
I'm especially interested in control flow/error patterns in rust as I ...
3
votes
0
answers
34
views
Created client server with read and write from both side
I have created client and server which can read and write from both side in client as well server. So what more improvement can be done so the code should be performant and better?
Following are three ...
-4
votes
0
answers
28
views
Trying to create full-duplex tcp server [closed]
I am trying to create full duplex server, I have implemented this rust code but it is not working, so what could be modification need to be done to make it works.
client.rs
...
3
votes
1
answer
60
views
Rust Wake-on-LAN CLI
I'm new to writing rust code, and looking for any alternate approaches to writing this code or changes to make it more idiomatic, and readable.
My use of traits, specifically, I dislike. It feels like ...
5
votes
1
answer
154
views
+200
Sand simulation in Rust
I am working on this project to learn Rust and a bit of Web Assembly. The rendering is done in JavaScript which I do not really care about so I will not post. I would like to receive some harsh ...
1
vote
0
answers
48
views
Rust minesweeper grid generator code design
I wrote this not really to create a minesweeper game, but to practice using some of the "rusty" (but not only) design patterns and improving my code structure.
I would appreciate a review of ...
4
votes
0
answers
67
views
Implementation of Kirkpatrick-Seidel convex hull algorithm and comparing against Jarvis-March
Introduction
I wanted to implement the Kirkpatrick-Seidel(KPS) convex hull algorithm and chose Rust as my language. I referred to the original KPS paper and tried to implement as closely it as ...
2
votes
0
answers
65
views
+100
ASHv2 implementation from scratch - host, transmitter and listener
I am currently implementing the EZSP and the underlying ASHv2 protocols in Rust with the intention to use them on an embedded smart home gateway to control ZigBee devices.
In this review I present you ...
4
votes
1
answer
61
views
Parsing command line arguments with CLI
I'm new to rust, and this is my very first rust program.
I'd like to write a simple CLI app to help me running some Git command on multiple repositories.
Since my goal is learning rust, I force myself ...
5
votes
3
answers
673
views
Rust: Command line menu in ASCII table
Specific areas in which I'd love to get feedback:
Is it good to have the Command struct own the Strings (...
3
votes
0
answers
66
views
Sum all numbers touching symbols in 2D grid (Advent of Code 2023 Day 3, Part 1)
Please offer suggestions to my below Rust approach for solving AoC 2023 Day 3, Part 1. The code is functionally correct, so I'm interested in understanding how I could have solved it in a more ...
4
votes
1
answer
72
views
Simple Redis implementation in Rust
This is a very tiny implementation of Rust that uses redis serialization protocol (RESP). I implemented it as one of code crafters challenges. I have less than a few month experience in Rust, so it ...
10
votes
2
answers
1k
views
Beginner Rust Todo app
I am trying to use the practices that I have learnt from the rust book. Any advice is welcome. Please feel free to be as nitpicky as possible.
...
3
votes
1
answer
117
views
RANDEVU - Rust crate implementing a simple algorithm I invented
I've created a simple algorithm which I've implemented in Rust and published it as a crate on crates.io.
https://crates.io/crates/randevu
While I do think my code is pretty clean and idiomatic, I ...
3
votes
1
answer
203
views
Taking array of numbers, having a max weight, and distributing excess weight to ln max weight numbers
The goal is to take an array of numbers, have a max weight (saying 40%), and if any number above the max_num = sum * weight is present, remove the excess and ...
3
votes
1
answer
96
views
Rust - idiomatic file search
I'm learning Rust. Could you share some tips for improving this code so it's more idiomatic and functional? I would prefer to stick to the standary library, and avoid unnecessary sorting or memory ...
3
votes
0
answers
60
views
Simple truss stiffness matrix calculator in Rust
I recently developed this calculator for some FEA homework i had. I'm still trying to familiarize myself with fundamental rust concepts like the ownership and borrowing. Pls let me know if there is ...
6
votes
1
answer
144
views
Odometer in Rust
I am trying to implement an odometer in Rust. This should a be an iterator that yields items of type [u16; N] and it should be generic over const ...
0
votes
1
answer
87
views
Handling default std::io::Error in Rust
I'm really new to Rust with less than a day of rusting. I'd like to know if the following code is ok or could it be written somehow better, and specifically, which would be the preferred way to handle ...
3
votes
0
answers
86
views
Rust ffi wrapper for barcode scanning library
I'm the maintainer of the zxing-cpp library, a barcode image processing library written in C++. I recently decided to invest in a Rust wrapper library/crate that is now on crates.io. It is basically a ...
4
votes
0
answers
60
views
A safe building block for self-referential structs in Rust, without macros
I recently had this (admittedly slightly crazy idea) on how to design a building block that can be used in safe Rust to build self-referential structs. Unlike gsrs or selfref it works completely ...
5
votes
1
answer
433
views
High Performance Matrix Multiplication is not very high speed, why?
I would appreciate a review of the following Rust implementation of high performance matrix multiplication.
After reviewing available literature, including Anatomy of High Performance Matrix ...
2
votes
1
answer
82
views
Rust Singleton Design Pattern using Lazy static initialization
In my current project there is a lot inter dependency between different structs, so instead of having Arc<Struct> as members for each of the dependent ...
4
votes
0
answers
106
views
A simple local API proxy
Recently I needed to support someone who wanted to ingest some data from on of our API's but had tooling that struggled with the authentication bit. While I'm sure there are some off-the-shelf ...
6
votes
1
answer
296
views
AVX2 8x8 Float Matrix Multiply in Rust
I'm interested in a fast 8x8 32-bit float matrix multiply in Rust, assuming availability of AVX2. After learning about the AVX2 intrinsics, here is what I came up with:
...
9
votes
1
answer
279
views
Construct a performant sieve of Atkin in Rust
I have implemented the sieve of Atkin in Rust. It can find all primes till 1,000,000,000 in 4.5 s using 34.4 MiB on my 1.4 GHz machine. This is a direct implementation (with some optimisations made ...
0
votes
2
answers
173
views
How to replace filter and map with filter_map? [closed]
The following sample code is for finding DIGIT_WORDS and their first occurrence in sentence line (Rust Playground)
...
5
votes
1
answer
84
views
Local Search Engine in Rust
I made a simple search engine using the xkcd API in Rust which turned out better than I'd hoped for!
I decided to use tf-idf as a way to rank results, which I feel like has some room for improvement. ...
6
votes
1
answer
82
views
Future struct that prints duration until it is Ready
I'm going through some exercises to learn about working with Pins. In the followinge example, I'm implementing Future for a wrapper around another Future. Calling poll on the wrapper will print the ...
4
votes
2
answers
96
views
Make a config, that is periodically refreshed by a background thread, easily accessible to the rest of the program
I'm learning rust by implementing simple use-cases that are common and trivial in other languages. Recently, I decided to prototype a small component for retrieving some "config" from a ...
4
votes
1
answer
148
views
Custom derive macro to create getters and setters
To learn how custom derive macros work in Rust, I decided to create a simple derive macro to provide getters and setters for a given struct.
It would be used like this:
...
2
votes
1
answer
105
views
Basic HTTP server implementation in Rust
I have made a basic HTTP server implementation in Rust. I have used frameworks like Actix-web in the past but the purpose of this code was learning and experimenting. I wanted to work as "low-...
5
votes
1
answer
159
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 ...
5
votes
1
answer
273
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 ...
3
votes
1
answer
172
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.
...
4
votes
1
answer
264
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 ...
4
votes
1
answer
66
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 ...
6
votes
1
answer
201
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
57
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, ...
3
votes
0
answers
47
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 ...
6
votes
1
answer
162
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 ...
4
votes
1
answer
75
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 ...
5
votes
0
answers
35
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 ...
3
votes
1
answer
159
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 ...
0
votes
0
answers
50
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 ...
4
votes
1
answer
99
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 (...
3
votes
1
answer
119
views
Create a String from the part of the vector
I want to create a String from the part of the vector.
My code:
...
2
votes
0
answers
62
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 ...
5
votes
1
answer
149
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 ...