As of May 31, 2023, we have updated our Code of Conduct.

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
1 vote
2 answers
519 views

Observer pattern in Rust

A simple implementation of the Observer pattern in rust. The Observable constructor (::new) is called with a subscription function which will be called every time ...
Luke Skywalker's user avatar
4 votes
0 answers
395 views

A safe type-erased Fn Pointer in rust that can be used to call associated and regular function

I am implementing a callback method to replace the use of generics. For maximum performance, it is not allowed to use Box and I also don’t want to use ...
JiaHao Xu's user avatar
  • 141
2 votes
1 answer
160 views

Longest common subsequence — recursion and memoization

...
avamsi's user avatar
  • 155
2 votes
1 answer
442 views

Solution to LeetCode Two Sum problem in Rust

It's taking 2.4 MB of memory and 20 ms. It's my solution for Two Sum problem on LeetCode. How can I make it better using closures and other stuff? Kindly review the code. ...
analogbeing's user avatar
4 votes
0 answers
124 views

LeetCode 1632: Rank Transform of a Matrix in Rust

This is a problem-solving code for LeetCode 1632. Given an \$m \times n\$ matrix, return a new matrix answer where ...
prehistoricpenguin's user avatar
4 votes
1 answer
263 views

Rust Persistent Red Black Tree Implementation

Below is my implementation of a persistent red black tree in Rust. I have a few questions about potential improvements. Currently the data and nodes are stored in referenced counted pointers. Is this ...
Someone's user avatar
  • 161
2 votes
0 answers
43 views

Rust program to create mail.tm accounts

I have created a rust program to create https://mail.tm accounts, but I think there are things I could have done better. Are there things I can do to improve performance? Are there any unnecessary ...
cavalry1223's user avatar
2 votes
1 answer
947 views

Rust returning multiple errors

I am learning Rust and I would like to know what is the idiomatic way of writing a function that could run into multiple error types. For instance, in the function <...
Yohannes Kifle's user avatar
5 votes
1 answer
103 views

Parallel word recognition in a Non-deterministic finite automaton in Rust

I have implemented a simple NFA that recognizes words in parallel. All the code is on GitHub, here. A main recognizes method tells if a ...
alexfertel's user avatar
4 votes
0 answers
119 views

Small generic helper library for working with recursive data structures

I've written a small rust library that solves rust's problems with using recursive data types (e.g, linked lists). using the library, you can use ...
user3329719's user avatar
3 votes
2 answers
109 views

Possible improvements to window swallowing program?

I have written a small program that swallows windows. It works in X.org using the xcb library. This is my first rust program but I have lots of other programming experience. Any general improvements ...
EmperorPenguin18's user avatar
6 votes
1 answer
266 views

Caesar cipher/beginnings of a crypto library in Rust

As a hobby project (and to learn the language), I'm working on a crypto library in Rust. The following is a component thereof, which implements encryption with and the cracking of the Caesar cipher. ...
Egg-Fault's user avatar
4 votes
1 answer
106 views

Async streaming of Reddit posts

roux is a Rust library that wraps the Reddit API. Neither Reddit nor roux provides a stream-like interface for obtaining the ...
Florian Brucker's user avatar
3 votes
1 answer
399 views

Simple terminal Game of Life in Rust

I've been learning Rust for a few weeks in my free time, and as a first project I decided to make a simple terminal Game of Life program (without UI, that might come later). It just starts with a ...
Francisco Gallego Salido's user avatar
2 votes
1 answer
134 views

Simplify a Unix-style absolute path

I have a match arm in rust, I think it may be simplified, but after googling and read books, I haven't find the solution. Especially for the ...
prehistoricpenguin's user avatar
4 votes
1 answer
217 views

Snake game in rust

I made a small rust snake game in order to teach myself rust. I would like to know what I am doing well and poorly, and how to improve my rust code Cargo.toml ...
Tornado547's user avatar
3 votes
1 answer
113 views

Rust Locker Problem Number Theory

The Locker Problem is as followed: Twenty bored students take turns walking down a hall that contains a row of closed lockers, numbered 1 to 20. The first student opens all the lockers; the second ...
amicharski's user avatar
6 votes
2 answers
142 views

Rust Simple Stats Program

I am brand new to Rust and want to know if there are any convention violations in my code and ways how I can make it more readable: ...
amicharski's user avatar
6 votes
0 answers
117 views

Efficiently generate distinct subsets which sum to a particular value

Related: Find all distinct subsets that sum to a given number This code is supposed to efficiently generate all subsets of a list such that the subset's values sum to a particular target value. For ...
coriolinus's user avatar
3 votes
0 answers
66 views

Add rows to a table in rust (code may not be safe?)

I'm trying to implement a sql-like in-memory database. Here is my code: ...
Ezra's user avatar
  • 131
1 vote
1 answer
80 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 ...
BusyAnt's user avatar
  • 639
5 votes
1 answer
306 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 ...
khalilw1's user avatar
-2 votes
1 answer
168 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? ...
ANimator120's user avatar
1 vote
1 answer
94 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-...
jmcph4's user avatar
  • 198
5 votes
1 answer
161 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 ...
sfbea's user avatar
  • 61
2 votes
1 answer
152 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 ...
Accumulator's user avatar
1 vote
2 answers
2k 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 ...
prehistoricpenguin's user avatar
0 votes
1 answer
489 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 ...
prehistoricpenguin's user avatar
7 votes
1 answer
1k 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 ...
Toni Jarjour's user avatar
7 votes
1 answer
314 views

Binary Heap Implementation in Rust

I'm learning Rust by implementing basic data structures and algorithms. I implemented a binary heap (max heap): ...
ryanzidago's user avatar
1 vote
0 answers
131 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 ...
Padriton's user avatar
1 vote
1 answer
100 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: ...
prehistoricpenguin's user avatar
4 votes
1 answer
630 views

Rust implementation of next-permutation

I am translating this next permutation algorithm in C++: ...
prehistoricpenguin's user avatar
0 votes
1 answer
38 views

Function returning a vec with prime factors of number

See code below and my comment with questions: ...
Antonin GAVREL's user avatar
4 votes
1 answer
288 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, ...
fpezzini's user avatar
  • 306
3 votes
1 answer
163 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 ...
Padriton's user avatar
1 vote
2 answers
271 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: ...
analogbeing's user avatar
2 votes
1 answer
104 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: ...
Padriton's user avatar
2 votes
0 answers
187 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 ...
Dimitri Bobkov's user avatar
1 vote
1 answer
634 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 ...
aonemd's user avatar
  • 145
9 votes
3 answers
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 ...
user4035's user avatar
  • 293
3 votes
1 answer
197 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 ...
Antonin GAVREL's user avatar
2 votes
1 answer
120 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. ...
analogbeing's user avatar
6 votes
1 answer
166 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: ...
Jonathan Woollett-light's user avatar
7 votes
1 answer
91 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 ...
Zeta's user avatar
  • 19.1k
2 votes
2 answers
117 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 ...
Alex's user avatar
  • 265
1 vote
1 answer
119 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 ...
jlim's user avatar
  • 103
3 votes
1 answer
46 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 ...
slebaron's user avatar
6 votes
1 answer
343 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 ...
muffin's user avatar
  • 63
6 votes
1 answer
436 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 ...
apilat's user avatar
  • 263

1
3 4
5
6 7
16