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
18 views

Simple Hangman implementation in Rust

I'm starting out with Rust and decided to implement a game of Hangman. Can you please provide general feedback on the code? I've already identified some lines (see comments ...
3
votes
1answer
46 views

Rust Book Ch 13 Closures with Generic Parameters and HashMap for memoization

I have been reading through the rust book. I have made it to chapter 13, at the end of the section called (Storing Closures Using Generic Parameters and the Fn Traits) a couple of improvements are ...
0
votes
0answers
32 views

I'm passing a lot of &mut ctx around, is there a better way to do this? [closed]

(Full code at https://github.com/dahosek/gftopdf2). I've written a first pass of a small library for reading the GF files output by Metafont. What I'm not too crazy about is that for the 11 distinct ...
-2
votes
1answer
34 views

Idiomatic Approach to Filter Struct Field - Rust

I frequently need to find then remove something from some Vec<> type struct field. Does the following represent an idiomatic approach to doing this? ...
1
vote
1answer
58 views

Minimal list definition in Rust

As a purely pedagogical exercise, I've been trying to use Rust's (very expressive) type system to define the bare minimum one might expect from an ordinary list type. While there's likely a higher-...
4
votes
1answer
69 views

Convex polygon-polygon swept collision test

Currently working on a pre-solve collision library. My goal is to have it be potentially usable in potential video game projects of mine, so time constraint is small as this should be used in a game ...
2
votes
1answer
62 views

A simple console in Rust that stores variables runs commands

I'm a C/C++ programmer and this is my first Rust program. A heavy simplification of the console system like used in Quake and Source engine games, that lets you set variables and run commands. I'm ...
1
vote
2answers
59 views

How to append values into existed Vec with iterator

I have a Vec with value default [0], and then I want to append into the vec with an iterator which is read from stdin, now my code is not performant since I use an insert to shift all the values ...
0
votes
1answer
25 views

How to collect reference values from hashmap?

I have written a code snippet to use HashMap<String, Vec<&String>> as the main data structure, and finally, I want to return a collected ...
7
votes
1answer
84 views

Count characters, words, and lines in files (wc in rust)

I wrote a barebones version of wc in rust. wc is a program that counts the number of characters, words, and lines in a file and ...
4
votes
0answers
45 views

Binary Heap Implementation in Rust

I'm learning Rust by implementing basic data structures and algorithms. I implemented a binary heap (max heap): ...
1
vote
0answers
31 views

Snake game in console

I made a snake game implementation in console with rust. Would like to hear what I'm doing wrong and what can be improved. main.rs ...
1
vote
1answer
72 views

How to make this special binary-search algorithm more rusty?

I am solving one binary search problem in LeetCode. I have accomplished such code: ...
4
votes
1answer
123 views

Rust implementation of next-permutation

I am translating this next permutation algorithm in C++: ...
0
votes
1answer
32 views

Function returning a vec with prime factors of number

See code below and my comment with questions: ...
4
votes
1answer
81 views

Comparing Poker hands in Rust

I found this interesting challenge in Exercism. This is my approach to comparing poker hands in Rust. I've strived for code clarity. I wish I had figured out how to only implement Ord or PartialOrd, ...
3
votes
1answer
87 views

Tic-tac-toe implementation

I created a tic-tac-toe game implementaiton in rust. What I can do to make this tic-tac-toe code a better code? game.rs ...
1
vote
2answers
94 views

Counting numbers that have an even number of digits

I solved this problem: given an array/vector of numbers, return how many of them contain an even number of digits. Constraints: ...
2
votes
1answer
51 views

Pseudo-random number generator & password generator

I've started learning Rust and decided to implement something on my own from scratch. I've implemented a PRNG and I use it to generate random passwords. Project tree: ...
2
votes
0answers
54 views

How should I go about implementing rust into the unity3d engine?

Recently, I've explored using rust as a scripting language for unity. My current method involves creating a DLL from rust, and loading it into my game at runtime. It requires that the user use a ...
1
vote
1answer
91 views

Parsing financials from a YAML file. Is this normal/idiomatic in Rust?

I wrote this Rust code to parse my financials from a YAML file and my main concern is the large match branches (although general code review is welcome; still a ...
9
votes
3answers
1k views

n-th Fibonacci number with memoization

I am learning Rust and decided to create a simple program to calculate n-th Fibonacci number. It uses a vector for memoization. The program works, but what would you suggest to improve here? Maybe ...
3
votes
1answer
86 views

Playing with unsafe code: Sending files over UDP

First of all, I am here to explore unsafe features of Rust, if you are the kind of guy who likes "safe" Rust and will start nagging about using safe features of Rust I will still happily ...
1
vote
1answer
77 views

Returning maximum number of consecutive 1s in list of binary numbers

This is what I implemented in Rust to get the maximum number of consecutive 1s in list of binary numbers. ...
6
votes
1answer
153 views

Calculating average value of points around given point in a wider field

I need to calculate the average value of points around a given point in a wider field. For this I have a function: ...
5
votes
1answer
63 views

Pipeviewer: A small “pv” Rewrite

If you ever had to pipe a large amount of data from some program foo into another program bar, you're probably familiar with the ...
2
votes
2answers
52 views

Kattis 'Driver's Dilemma'

The full problem description can be found here, a slightly trimmed version below: A car driver is travelling on an isolated road (no gas stations, houses, or cell phone coverage). The driver glances ...
1
vote
1answer
70 views

initialize 2d array using 12 tone algorithm with Rust

a rust exercise in initalizing a 12x12 array based on the algorithm for twelve tone matrix described here: https://www.instructables.com/Create-a-Twelve-Tone-melody-with-a-Twelve-Tone-Mat/ i copy ...
3
votes
1answer
39 views

List parsing for 'cut'

I'm new to Rust and am learning by implementing my own version of cut. This is a snippet that parses the <list> of ranges ...
5
votes
1answer
92 views

Rust Book: The Twelve Days of Christmas

In order to learn Rust I'm going through The Rust Book and did the implemented a program for the following exercise: Print the lyrics to the Christmas carol “The Twelve Days of Christmas,” taking ...
6
votes
1answer
98 views

N-dimensional array in Rust

I am practicing Rust by creating data structures, such as this N-dimensional array. The purpose of this structure is to easily define and address into arbitrarily-deeply nested arrays without having ...
4
votes
1answer
38 views

Parsing a u8 separated vector of FromStr from a BufRead

I need to read a vector of e.g. integers from a stream, usually from stdin but sometimes also from a file. The input is always less than a megabyte, and is sometimes separated by commas and sometimes ...
1
vote
1answer
81 views

Company database REPL program in Rust for Chapter 8 of The Book

Using a hash map and vectors, create a text interface to allow a user to add employee names to a department in a company. For example, “Add Sally to Engineering” or “Add Amir to Sales.” Then let the ...
3
votes
1answer
56 views

Programming Pearls — Column 1: Sorting unique numbers with bitfield

I've implemented a simple program to sort an input of unique numbers given as decimals on a separate line. The idea is, since all numbers are unique, to use a (long) bitfield where a 1 on index n ...
7
votes
2answers
204 views

Idiomatic use of `Option` and `unwrap` in mean, median and mode Rust program for Chapter 8 of The Book

I've recently finished Chapter 8 of The Book and have started doing the exercises at the end of the chapter. This post pertains to the first exercise which involves writing a program to output the ...
4
votes
1answer
128 views

Searching for an idiomatic Rust implementation of Minimum Edit Distance (LeetCode #72)

I am solving LeetCode Dynamic Programming challenges (this one is #72, at https://leetcode.com/problems/edit-distance). Here below, I've implemented a Rust solution for the minimum edit distance ...
1
vote
1answer
33 views

Cat clone with unit tests

This is a clone of the cat utility. The goal of this exercise was to get comfortable doing basic tasks in a new language, figure out how to set up testing, etc. So ...
1
vote
1answer
89 views

Parallel map in Rust

A parallel map written in Rust. I am new to Rust and wondering if there is things that could be done better or more efficiently. ...
1
vote
0answers
55 views

Vega lite plot rendering with Yew (rust + wasm)

I wanted to render some Vega plots in a rust+wasm web application I've been building with Yew. I'm a bit new to Rust, so I'm looking for feedback on runtime safety and stylistic issues. I was ...
6
votes
2answers
91 views

Command-line Tic-Tac-Toc in Rust

I implemented Tic-Tac-Toe in Rust to learn the language. I split the implementation into two files: game.rs contains the actual game logic, and ...
2
votes
1answer
63 views

Temperature converter in Rust

I've just started learning myself Rust. I am practicing with the exercises from the book available on the official website. Here is my attempt at the temperature converter exercise at the end of ...
1
vote
1answer
50 views

Advent of Code 2020 - Day 3: tobogganing down a slope

Previous: Advent of Code 2020 - Day 2: validating passwords Problem statement I decided to take a shot at Advent of Code 2020 to exercise my Rust knowledge. Here's the task for Day 3: Day 3: ...
0
votes
1answer
104 views

Advent of Code 2020 - Day 2: validating passwords

Previous: Advent of Code 2020 - Day 1: finding 2 or 3 numbers that add up to 2020 Next: Advent of Code 2020 - Day 3: tobogganing down a slope Problem statement I decided to take a shot at Advent of ...
0
votes
1answer
220 views

Handling shared state between actix and a parallel thread

In order to learn rust and concurrency , im trying to share a common hashmap between actix web server and a parallel thread Theres one thread which updates a hashmap with the current timestamp every ...
0
votes
1answer
72 views

Advent of Code 2020 - Day 1: finding 2 or 3 numbers that add up to 2020

Next: Advent of Code 2020 - Day 2: validating passwords Problem statement I decided to take a shot at Advent of Code 2020 to exercise my Rust knowledge. Here's the task for Day 1: Day 1: Report ...
1
vote
1answer
59 views

The Rust Programming Language Pig Latin Exercise

This is my implementation of the Pig Latin recommended exercise in The Rust Programming Language book. I am using the unicode segmentation crate to split the string into words while also keeping the ...
7
votes
2answers
321 views

Calculate all the prime numbers between two given numbers

I've made an application that calculates all the prime numbers between two given numbers and prints then into a .txt document... anything I can improve? ...
5
votes
1answer
112 views

RUST: How can I optimize this password cracking algorithm?

I made this project in my free time to try to crack a 4x hashed md5 with a couple of hints but I'm looking for ways I can optimize this algo because it's pretty slow and I know you could probs use ...
3
votes
1answer
104 views

Matching brackets in Rust

I implemented the solution to the classic Matching Brackets problem: Given a string containing brackets [], braces {}, parentheses (), or any combination thereof, verify that any pairs are matched and ...
-1
votes
1answer
74 views

How to eliminate derefs?

Spoiler: Advent of Code 2020 Day 8 Your flight to the major airline hub reaches cruising altitude without incident. While you consider checking the in-flight menu for one of those drinks that come ...

1
2 3 4 5
12