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
0
votes
0answers
21 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
112 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
61 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
42 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
25 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
93 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
190 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
54 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
60 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: ...
6
votes
0answers
84 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
80 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
49 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
133 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
56 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
36 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
132 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
43 views

Merging (not removing) duplicated elements in a vector

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

Rust: Flattening nested struct to Vec<T>

I have a struct which nests other structs like following: ...
5
votes
1answer
69 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
70 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
43 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
46 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
75 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
210 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 ...
3
votes
1answer
120 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
52 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
179 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
49 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
131 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 ...
3
votes
1answer
117 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
140 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
53 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
57 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
289 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
96 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 ...
2
votes
1answer
49 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
170 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
56 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)...
13
votes
2answers
2k 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
156 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
1k 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
123 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
86 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 ...
3
votes
2answers
811 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: ...
7
votes
1answer
302 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-...
5
votes
1answer
344 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
70 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)....

1 2 3 4 5 9