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
4
votes
1answer
35 views

Wavefront 3D Obj parser/viewer

For learning Rust I decided to make a 3D .obj viewer. I wrote a simplified OBJ parser without materials that only supports triangles. Considering I'm completely new to Rust and don't really know ...
4
votes
1answer
37 views

Simple income/expenses accounting program

I've decided to start working on a budget application for the purposes of getting started on Rust. In its current form this program takes given expenses and income and tells the user whether they have ...
-1
votes
1answer
37 views

Trying to convert struct with hashmap member

Consider a struct: struct RawData{ pub a: HashMap<String, String>, pub b: HashMap<String, String>, } which should be converted in a struct with ...
3
votes
1answer
41 views

Bin Numbers from stdin

I often like to get a feel for a text file containing a lot of numbers quickly by making a histogram. One can do this in plotting software like Gnuplot, but sometimes having something in the terminal ...
1
vote
1answer
75 views

Exposing a simple struct using Rust FFI

I am trying to expose a simple struct via FFI. Is this the best way to do it? I am not 100% sure about the get_text function. This is taking the string out of the struct and cloning it before ...
5
votes
2answers
91 views

Compute Manhattan distance from origin given a set of left-right-step directions

I am solving the problems for Advent of Code 2016 to learn Rust programming. The prompt for the first problem can be summarized: I start at position 0,0 on a regular grid. I am given a set of ...
4
votes
1answer
55 views

Game of Life in Rust-lang

I decided to implement Conways Game of Life for my first project using Rust. I also haven't had much code review ever, and have been looking for a good critique of my code so I can improve my skills. ...
1
vote
1answer
39 views

An asynchronous logger

I've written a simple asynchronous logger (playground): ...
2
votes
0answers
26 views

Using best practice with complex iteration

I'm new to Rust so I'm still learning how to use best practice in complex examples. Below is some code I've used in one of my programs, a simple implementation of a standard neural network. Here is ...
2
votes
2answers
106 views

Miller-Rabin Large Prime Generator in Rust

I implemented the Miller-Rabin prime test in Rust and made a program to generate large primes. I have also implemented the same program in C and Haskell and the Rust version is the slowest. I am ...
0
votes
0answers
17 views

Getting redis sentinel info in Rust

I've cobbled together some Rust code to display Redis master/slave information. As a Rust newbie, I'd appreciate some review feedback. ...
3
votes
0answers
51 views

Console Snake Game

I am beginning to learn rust and I created this snake game for practice. I am looking for some feedback on my code. main.rs ...
3
votes
0answers
33 views

Rust Iterator that correlates a slice with itself

In my effort to learn Rust I've tried implementing an Iterator that splits up a buffer in two halves, and correlates both halves by sliding them over each other with different positions (lags). You ...
3
votes
0answers
44 views

SHA256 implemented in Rust

I just finished making an implementation of a SHA256 hashing function (https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf) in Rust and I was looking for some feedback. As far as I can tell it ...
2
votes
0answers
30 views

Rust HTTP Requester

I am writing an HTTP client for terminal, similar to curl, as a learning exercise. There's one limitation it suffers from and that is that it won't return until the client closes the socket. I fixed ...
3
votes
1answer
45 views

Pidfile single process instance mechanism

I'm writing a system daemon in Rust that may be started by the user manually. Only one instance of the daemon should be running at a time so I have created a pidfile locking mechanism to prevent ...
4
votes
1answer
77 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
228 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 ...
6
votes
1answer
85 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
24 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
71 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
28 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
170 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
42 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
62 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
20 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
73 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
48 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 ...
2
votes
1answer
33 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
23 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
29 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
50 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
35 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
47 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
56 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
66 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
31 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 ...
4
votes
2answers
98 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
31 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
106 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
42 views

Merging (not removing) duplicated elements in a vector

There's a struct named Player containing name and stat: ...
2
votes
0answers
23 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
32 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
32 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
119 views

Rust: Flattening nested struct to Vec<T>

I have a struct which nests other structs like following: ...
5
votes
1answer
68 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
58 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
31 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
44 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 ...