Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

3
votes
0answers
27 views

Linked List In Rust

I am still learning Rust and I think I have a long way to go. This question is from exercism.io. I am posting here to get some more reviews and suggestions to improve my code. Linked list aren't a ...
4
votes
0answers
200 views

Wait free triple buffer primitive

I'm trying to write a triple buffer that's wait free for a update + render loop after being bitten by lock starvation one too many times (on a different project, using a library). For reference, a ...
4
votes
0answers
41 views

Simple function to create Tokens from user input

I am new to programming in Rust and as an exercise I was making a simple Lottery checker program. It has a simple menu, the user enters a number for the corresponding option such as 'Add a line', '...
2
votes
0answers
20 views

Modelling a program with modules, symbols, and dependencies

My scenario is the following: I'm modelling a Program which has many Modules. Each Module has Symbols, some of which pointing at dependencies, which are other Modules. So a Module can be pointed to by ...
1
vote
1answer
50 views

Vector calculation in Rust

Hi I am trying to get into Rust by implementing a small library for vector calculations. I am mainly asking to point out whether I chose a valid approach. I also am interested in comments on the ...
3
votes
0answers
18 views

Connect to a database with Diesel

New to Rust and would like some clarification on idiomatic and readable use of Result and Error types. Here I'm simply connecting to a database using Diesel. In my opinion, the use of match and Boxing ...
4
votes
0answers
159 views

Simple routing in Rust

After my last attempt, I started to learn Rust again. This time I wrote a simple HTTP router. I would appreciate it if you could help me to fix my mistakes. Here is the link of the repository main....
1
vote
0answers
32 views

Tic-Tac-Toe Game in Rust

I recently discovered to joys of rust programming and I have written a tic-tac-toe game. I was hoping for some feedback on how it is made. (The reason split and <...
3
votes
0answers
52 views

User registration in Actix w/ DynamoDB

I am trying to puzzle out api based user registration for a service I am building, but I have a strong feeling that my code is not optimal. It feels like passing "state" in the way I did prevents the ...
0
votes
0answers
17 views

Idiom: replacing a slice with a suffix of that slice (write_all loop)

As you probably already know, the Unix I/O primitive write is not guaranteed to write out all of the data in the buffer you give it; you may be obliged to loop ...
7
votes
0answers
61 views

(Lisp in (Rust))

I loved Norvig's Lispy, and made the first version of it in Rust, to learn Rust. I would love your thoughts :) A few specific questions: Is there a way to write ...
3
votes
0answers
37 views

Recursively create a tree in Rust

This code is meant to take a rectangular area, and randomly divide it up into smaller rectangles in a binary tree. I'm somewhat new to Rust. I'm concerned mostly about the ...
3
votes
1answer
29 views

Pulling images from Windows 10 Lock Screen to a different folder

Windows 10 has an interesting feature where it will display "fun facts" and images on the lock screen. Occasionally, these images are something I would want to use for a background. These images are ...
1
vote
0answers
20 views

Calculate mean of vector primitive numerical values generically

I'm trying to write a generic mean function for all values within an Vector of generic numerical primitive type. Could the following implementation be possible ...
0
votes
0answers
25 views

Single chars mapped to enums in Rust

I'm writing a simple program to parse lines read from a file. As I'm new to Rust, I wonder if I'm creating too much boilerplate. A sample line in the file looks like this: ...
1
vote
1answer
39 views

Clone Vector in rust except at one index [closed]

Let's consider you want to clone all items of a vector orig except the item of index i should be taken from alternative value <...
3
votes
0answers
29 views

Simple one-time pad in Rust

I am new to rust and to start learning the language I decided to implement a simple one-time pad encryption program. The part I am least sure about is the reading and writing from the files. Ideally ...
3
votes
0answers
34 views

Parsing version from Cargo.toml

I want to get version from Cargo.toml and use the value inside my app. Here is a function I wrote: ...
4
votes
0answers
52 views

Generating integer partitions

I've tried to implement integer partition algorithm as described in blogpost below (author implemented it in Python): Generating integer partitions I'm still trying to learn best practices in ...
3
votes
0answers
59 views

Rust book chapter 8 department challenge

I am just starting my journey in to rust and will gladly accept any feedback you can give me. This is the third exercise in the Rust book chapter 8. Exercise description Using a hash map and ...
1
vote
0answers
24 views

proc_macro derive for generatting getters in a struct for each type it contains

This is also on github: https://github.com/theypsilon/getters-by-type-rs ...
3
votes
2answers
80 views

Incremental Sieve of Eratosthenes using iterators

I am in the process of learning Rust and am still having some issues with borrowing and ownership. I find myself trying to borrow mutable references that are already borrowed as immutable references ...
1
vote
0answers
54 views

Incremental Sieve of Eratosthenes using unstable generators [duplicate]

I am in the process of learning Rust and am still having some issues with borrowing and ownership. I find myself trying to borrow mutable references that are already borrowed as immutable references ...
1
vote
0answers
26 views

Password Checker using Pwnedpasswords API in Rust

This takes a user password, hashes password to SHA1 and does a check against the Pwnedpasswords database. I know I need to use unwrap less and do more real checking to improve the clarity of errors. ...
2
votes
0answers
86 views

Parser for simple esoteric language in Rust

I am writing a compiler for esoteric language as one of my first Rust projects. I am using rust-pest to generate a parser. Since I'm new in Rust, code review would be great. Full source code can be ...
1
vote
1answer
41 views

Merging (not removing) duplicated elements in a vector

There's a struct named Player containing name and stat: ...
2
votes
0answers
22 views

Translating Python to Rust: reading a Salesforce ID from a string

As a first project in Rust, I'm translating an existing, working piece of Python code. This code's purpose is to convert a 15-character Salesforce Id (which is guaranteed to be ASCII, exactly 15 bytes ...
1
vote
0answers
31 views

Rust trait implementations for a Blackjack game

I am learning Rust. I have build a simple game (Blackjack) to get acquainted. The following code is the code which runs the game logic. The code is part of the larger codebase and works. In the rest ...
1
vote
1answer
27 views

Combine Filter to include and Exclude

I have some data which I want to filter. I have a collection of things to include and a second one of things to exclude. Currently I'm looping my data and filter once for the including and a second ...
2
votes
1answer
77 views

Rust: Flattening nested struct to Vec<T>

I have a struct which nests other structs like following: ...
5
votes
1answer
63 views

Sorting words by frequency

I'm doing a simple task in Rust after reading the Rust book: read a text file split it at whitespace sanitize words by removing non-letter characters sort the words by their frequency of occurrence ...
3
votes
0answers
53 views

Doubly linked list in Rust using raw pointers

I am practicing Rust by writing doubly linked list using raw pointers, Box<node> to allocate data on heap, Box::from_raw ...
2
votes
1answer
29 views

Checking against user input and returns a response based on that input

How could I use enums in the following block of code to simplify it? The block is a program that has a command interpreter that returns different data based on user input. Is there a way I could ...
3
votes
1answer
43 views

Find a valid english phrase that is identical to what the user entered, save a missing consonant

The Task: The user enters a path to a dictionary file (one word per line) and a phrase as system arguments. My code must then find phrases containing only valid English words, generated by removing ...
1
vote
1answer
58 views

Factorial Calculator with a basic BigUInt

This is my first rust program. I don't mind this being a strict review. What I want Reviewed? Idiomatic code. Performance improvements. Clean code! Program Requirements: Input a unsigned integer ...
2
votes
0answers
78 views

Type erasure in Rust

This is a very stripped-down version of a crypto library I am writing. There are cryptographic algorithms like RSA, DSA, ECDSA, EdDSA, ... which all have a similar pattern of having a private key, a ...
2
votes
1answer
64 views

Rust closure to be called on a cache miss

The official Rust book chapter 13.1 includes an exercise to expand on the example provided in the chapter: Try modifying Cacher to hold a hash map rather than a single value. The keys of the hash ...
4
votes
1answer
40 views

Rust version of basic functional prime stream - can this be made less clunky?

I'm looking at implementing the basic functional not-quite-Eratosthenes prime stream in Rust. I like to try it when I start learning a language. Here's the bog standard Haskell version: ...
2
votes
1answer
83 views

Rust: calculating mean, median, and mode for numbers from stdin

This quiz is on The Rust Programming Language online ebook. Given a list of integers, use a vector and return the mean (the average value), median (when sorted, the value in the middle position), ...
3
votes
0answers
38 views

Generic router in Rust

I am trying to make a router in Rust using Rocket.rs. I'd like to devise a way to use a default router for my more simple db tables that don't require different logic, to prevent rewriting the same ...
2
votes
1answer
82 views

Rust: exercise of employees and names

As I'm learning Rust using the second edition of the Rust book I solved the following exercise: Using a hash map and vectors, create a text interface to allow a user to add employee names to a ...
2
votes
1answer
97 views

Simple Brainfuck Interpreter in Rust

Not a long time ago, I got into Rust and I made a simple Brainfuck Interpreter. Now I want to get back to Rust and I would like some comments on my code: Just in case it's hard to read code from post:...
1
vote
1answer
74 views

Pig Latin in Rust

I feel like this code can be written in a better way but don't know how. Any help would be really appreciated. ...
2
votes
1answer
44 views

Batch downloading to file or memory

This is likely my first useful piece of Rust code. Planning to crate-ify it. It works. ...
0
votes
1answer
50 views

Computing a prime table in Rust

My objective is computing a table of primes up to n, where n is a natural number passed as an argument to the prime_table function. Here is src/lib.rs: ...
6
votes
1answer
144 views

Find the longest common sequence of two strings in Rust

I've attempted to solve a small coding challenge I found online as a nice way to begin learning Rust. The largest challenge I feel going in with Rust is how working with strings is so fundamentally ...
5
votes
0answers
58 views

Tetris clone in Rust using specs

In order to get a hang of the ECS paradigm of game making, I decided to try my hand at making a clone of Tetris. I am using the specs crate for Rust in order to ...
0
votes
0answers
34 views

A freelist in Rust

...
2
votes
1answer
35 views

Text interface for employee management in Rust

I'm in the process of reading The Rust Programming Language, and decided to do the 3rd task at the end of the 8th chapter. The description is as follows: Using a hash map and vectors, create a text ...
4
votes
0answers
130 views

Move-generation for chess in rust

In the last couple of days I have been programming a chess move generator in Rust from scratch. While it's intent is to be later used in a fully functional engine, where the speed of the move-...