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
31 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
10 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
50 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
48 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
21 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. ...
1
vote
0answers
73 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
34 views

Merging (not removing) duplicated elements in a vector

There's a struct named Player containing name and stat: ...
2
votes
0answers
17 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
27 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
26 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
50 views

Rust: Flattening nested struct to Vec<T>

I have a struct which nests other structs like following: ...
5
votes
1answer
57 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
48 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
28 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
53 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 ...
1
vote
0answers
48 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
53 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 ...
3
votes
1answer
39 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
66 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
35 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
71 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
92 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
64 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
43 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
48 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: ...
5
votes
1answer
99 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
45 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
30 views

A freelist in Rust

...
2
votes
1answer
34 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
124 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-...
1
vote
0answers
22 views

A syslog to Azure Log Analytics forwarder

I am using this code to forward my syslog logs (converted to json using syslog-ng) to Azure Log Analytics on an ARM board (since there is no official client for ARM)...
9
votes
2answers
1k views

Circular FIFO Buffer

I was bored the other day and got to wondering how I would implement a circular FIFO buffer in Rust. My goal was to create an implementation I could use on a bare metal microcontroller. This means no ...
0
votes
1answer
60 views

FizzBuzz in Rust [closed]

I want to make fizzbuzz method return the resolved value and then pass it to println!. Been having quite a problem with &str vs String. Wanted to use &str as return value as it's immutable so ...
4
votes
1answer
81 views

Decimal to Binary in Rust

As a beginner in Rust i am trying to practice Rust with some little programs so here is my implementation of Decimal to Binary. ...
3
votes
1answer
67 views

Temperature calculator in Rust

Just on a chapter 3 of Rust Book so not much good in Rust. so tried to implement a simple temprature calculator as suggest in this chapter. so i would like you guys to point anything you feel ...
2
votes
1answer
79 views

Second take at a stack based langauge

I recently asked for a review of a stack based language I made in Rust. I made a lot of changes since then and a lot has changed. Hopefully I haven't gone backwards in progress. Most notably: I ...
2
votes
2answers
210 views

Simple multithreaded chat server in Rust

I'm trying to develop a simple Rust chat server. I'm not a Rust expert and come from Java and Kotlin. This same server in Kotlin is: ...
6
votes
1answer
99 views

Traceroute implementation in Rust

I made this simple traceroute implementation using the libpnet library, which sends ICMP echo probes with an increasing time-to-...
4
votes
1answer
137 views

A Rust crate with both `main.rs` and `lib.rs` performing primality checking

Introduction I decided to get my feet wet in Rust by going ahead an implementing a full crate with the tests, documentation, and all other accompanying stuff. This is a toy implementation of a ...
2
votes
1answer
56 views

Catty: A mini cat clone in Rust

As part of my journey in learning the Rust programming language, I decided to make a miniature cat clone (catty) in it. The following is my code, which depends on clap for argument parsing (see below)....
2
votes
0answers
45 views

DOS header parser in Rust

Looking for feedback mostly on the from() and printf() implementations but I included everything for context. Please do not ...
5
votes
2answers
593 views

Fahrenheit and Celsius converter in Rust

I made a program that converts between Celsius and Fahrenheit. Is there any way that I could make this code more efficient and cleaner? ...
3
votes
1answer
104 views

Merge two sorted lists in Rust

I wrote the following code to merge two sorted lists. Is there a way I can improve it? Possible ideas (not sure how to implement them): Remove code duplication (setting the returning list node and ...
5
votes
1answer
85 views

Implementing a doubly linked list with smart pointers

I've been learning Rust for the past few days and I just passed the "Smart Pointers" chapter. To check what I've learned I've decided to implement a doubly linked list. My question is, is this ...
2
votes
1answer
81 views

Small stack based language in Rust

I made a small stack-oriented language in Rust. It tries to run anything it is given. To elaborate: Division by zero gives zero. If there is nothing on the stack and a request is made that involves ...
1
vote
1answer
50 views

Convert a type u16 number to a matrix (Vec<Vec<u8>> or array) of 4 x 4

I am a Rust newbie and I am not familiar with all the iterator options. This is what I have so far. How can I make this better or at least avoid collecting twice into a Vec? ...
1
vote
1answer
122 views

Rust Task Queue

The purpose of this program is to have one thread (main thread) working on I/O reading lines from a file and feeding it to a pool of worker threads whose job is to perform some processing on each line ...
2
votes
0answers
339 views

A multithreaded, growable vector with immutable elements, which has wait-free reads

I wrote a small vector with a few lines of unsafe Rust. The idea is to have a vector, which can be read from simultaneously, but it needs the ability to grow. To realize that, the storage is ...
3
votes
1answer
64 views

Temperature converter in Rust with input error handling

I started learning Rust a few hours ago with the Rust Book (2018 edition) and as part of one of the exercises decided to make a temperature converter. I wanted to make sure it handled all inputs ...