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.
885 questions
0
votes
0
answers
37
views
Builder pattern with nested struct
I've been looking on how to use Builder pattern on rust with structs, but all examples I've seen only use primitive data.
Given the structs:
...
8
votes
1
answer
372
views
S-expression parser in Rust
I wrote a toy s-expression parser, and I'd like to know if I can make it more Rusty.
I'm not terribly worried about the functionality. It's only a Rust exercise for me.
...
1
vote
0
answers
50
views
Async Rust UdpServer with Clean-Shutdown (using Tokio)
I'm new to Rust and trying to build an async Server.
The server should receive UDP packets, process them (which will include more network communication), and respond the result to the client.
I had ...
6
votes
3
answers
454
views
`repeat_and_join` function for strings and chars in rust
Background
I'm trying to write a helper function for constructing repeating strings with a separator.
...
7
votes
1
answer
240
views
Optimizing a Rust permutation chooser for the most subsequences
I had semi-recently asked a question (well a couple closely related questions) on math.stackexchange. The simplest question is phrased as follows: You are allowed to make 3 permutations of length n. ...
4
votes
1
answer
138
views
Higher-kinded types in Rust
Also posted on Reddit.
As a small personal exercise, I'm trying to implement a notion of higher-kinded types in Rust using type-level defunctionalisation based on the "Lightweight higher-kinded ...
1
vote
2
answers
152
views
Translating an image encoded as u32 to an array
I have a function in an embedded system which translates an image encoded in a 32-bit integer to 3x9 matrix (an array of arrays):
...
1
vote
1
answer
117
views
Creating functions that send and receive atomic messages in Rust paradigm
I'm converting a library from C to Rust, and I want to see if this is the optimal way to implement network communication. This ...
5
votes
1
answer
138
views
File system regex searcher
This is my first Rust project (I'm primarily a C guy). I want to know if my code is properly idiomatic (Rusty?). Also, are there any inefficiencies?
The code defines an iterator (...
2
votes
0
answers
102
views
Monte-Carlo pricing engine for a structured product
I'm implementing a Monte-Carlo pricing engine to price a structured product in Rust, using the usual Black-Scholes assumptions. This pricing engine is used in a (basic) gRPC server which receives all ...
1
vote
1
answer
85
views
Needleman-Wunsch algorithm with affine gap cost
Needleman-Wunsch is a bioinformatics algorithm used to align 2 sequences. The algorithm outputs the score of the alignment and a Vec containing all operations to reconstruct the alignment. I do not ...
5
votes
2
answers
427
views
Rust implementation of Euler problems
I'm starting to learn rust and figured my first simple project would be to solve some of the Euler problems. I'd appreciate if anyone could tell me where I might be ...
4
votes
2
answers
240
views
Simple Sieve of Eratosthenes
I've implemented this version of the Sieve of Eratosthenes in Rust, with inputs. I'm mostly pleased with it, but want to know if the input logic can be simplified, and if the sieve itself can be ...
4
votes
1
answer
118
views
LeetCode Rust solution for the Sliding Puzzle problem #773
Here is the solution to the LeetCode Sliding Puzzle Problem #773. The problem is to find the shortest solution for a 3 x 2 sliding puzzle.
I would appreciate any ideas to improve this code. But it's ...
3
votes
0
answers
116
views
MIDI router in Rust
I am working on a small MIDI router application for the Jack audio connection kit in Rust. The goal of the application is to route MIDI signals from an instrument to one or multiple applications in ...
5
votes
2
answers
159
views
Splitting Rust Strings into variables
I'm learning Rust and I'd like advice on how to make my code more idiomatic. I have a set of entries that are colon separated string-number pairs, a name and a size, like so:
...
7
votes
2
answers
1k
views
Program to find three cubes that sum to a fourth cube
I'm writing a Rust program that finds the "first five cubes that can be written as the sum of three distinct nonzero cubes", e.g. 216 = 6^3 = 3^3 + 4^3 + 5^3. The function looks like this:
<...
1
vote
1
answer
39
views
Basic Hybrid Logical Clock in Rust Performance Improvements?
I needed a very basic hybrid linear clock implementation for a project implementing MVCC. It gives me a perfectly incrementing clock that I can use to compare timestamps that can handle high load ...
6
votes
1
answer
104
views
Simple calculator app in Rust
To learn about Rust and parsing, I wrote a simple calculator that can solve problems involving the four basic operations (+, -, *, /) as well as exponentiation. For the sake of simplicity and ...
4
votes
1
answer
182
views
Poker Lite (AOC 2023 Day 7) using structs wrapped in an enum
I've been trying to learn Rust by working through Advent of Code 2023, specifically for day 7, part 1, here. It's Poker Lite:
You're given a list of hands. The input is formatted as ...
3
votes
1
answer
132
views
Type-state pattern and state management for credentials struct used with Spotify web API
I am implementing authentication with the Spotify web API as part of a larger project. Yes I know there are already crates that can handle it for me but that is no fun. I am implementing the auth code ...
1
vote
2
answers
127
views
Convert uppercase to title case
Following is my rust function to convert uppercase to titlecase (without removing the underscore). although I am able to achieve my goal but I don't think this is a good solution. Ignoring the nested ...
6
votes
2
answers
333
views
Bit manipulation to find a monochromatic clique on k vertices knowing all on k-1 vertices
I have a very hot segment of code in a large project. I've extracted the relevant segment and a toy example to illustrate it.
The project involves an unavoidable combinatorial explosion related to ...
4
votes
1
answer
418
views
Dependency Injection - Actix Web - Rust
I want to know how would I go about architecting an MVC architecture using actix-web.
I have a user_service which requires ...
3
votes
1
answer
62
views
Benchmarking type generic algorithms on type heterogenous problem sets in Rust
I need to benchmark the different code generations of a generic function in rust, for different type parameters. I ran upon this when developing differential equation solvers using ...