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
1answer
27 views

Concatenate two vectors and store the result

I code in Rust, but one doesn't need to be familiar with Rust to understand the question. We are given the two vectors, first and res. Our goal is to append res to first, and then to assign the result ...
5
votes
1answer
59 views

Simple expression evaluator in Rust

What follows is an evaluator for a toy expression language. The language includes functions of a single variable (with lexical binding), along with numbers and a way to apply functions to expressions. ...
1
vote
1answer
30 views

Patricia tree implementation in Rust

I've implemented a map using a Patricia tree, using u64 as keys. I would like general feedback on my code, but I have one thing that I think could be implemented in ...
0
votes
0answers
40 views

Rust Error Handling - Can this error handling be made cleaner?

Recently I started to learn Rust. I come from a mostly Java background, but spent roughly the last two years in Go. I am working on converting a small microservice that reads data from Kafka and ...
3
votes
2answers
80 views

Split string at given positions

Given a vector <Vec<usize>> of indices indicating where to split a string as follows: ...
1
vote
0answers
39 views

Convert PathBuf to file URL in Rust

I've implemented a custom trait on std::path::Path (and by extension std::path::PathBuf) with a method which turns the struct ...
5
votes
1answer
73 views

BST implementation in rust

I am looking for some feedback on my implementation of binary search tree in rust and I would appreciate someone taking the time to go through it and suggest any improvements or corrections as they ...
3
votes
1answer
45 views

Rust script to generate JavaScript asset list file based on directory contents

I'm new to Rust. I wanted to create a script to read the contents on a directory, and then generate a js file exporting this assets. I wrote this code, it works but I'm not totally happy with it. I ...
0
votes
0answers
41 views

Avoiding cloning references in a Specs system

I'm working on a card game using Amethyst's Specs crate and am fairly new to Rust (therefore I'm learning through the fight with the compiler). My first System is ...
4
votes
0answers
54 views

Barebones DNS Client in Rust

I'm starting to learn about networking and as a project I am building a really simple DNS client in Rust. Functionality to start was just to take a command line domain argument and sending a DNS A ...
-1
votes
1answer
38 views

Rust: lazy_static the strings from evdev codes [closed]

So I have this piece of code that produces following error: ...
1
vote
2answers
122 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 ...
3
votes
0answers
67 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 ...
2
votes
1answer
88 views

Longest common subsequence — recursion and memoization

...
2
votes
1answer
165 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. ...
4
votes
0answers
102 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 ...
4
votes
1answer
78 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 ...
2
votes
0answers
33 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 ...
2
votes
1answer
85 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 <...
5
votes
1answer
83 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 ...
4
votes
0answers
58 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 ...
3
votes
2answers
98 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 ...
0
votes
0answers
20 views

Fuzzy Search Table Widget in FLTK-Rs

I'm building a fuzzy search table widget in FLTK-RS. On my pretty decently spec'd machine I'm getting pretty laggy performance, does anyone have any thoughts on ways to improve this? If you'd like to ...
5
votes
1answer
87 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. ...
4
votes
1answer
56 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 ...
3
votes
1answer
125 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 ...
2
votes
1answer
81 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 ...
4
votes
1answer
104 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 ...
3
votes
1answer
68 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 ...
6
votes
2answers
111 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: ...
6
votes
0answers
70 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 ...
3
votes
0answers
55 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: ...
1
vote
1answer
62 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
102 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 ...
-2
votes
1answer
62 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
75 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
84 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
83 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
171 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
96 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
268 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 ...
6
votes
1answer
93 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
47 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
85 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
189 views

Rust implementation of next-permutation

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

Function returning a vec with prime factors of number

See code below and my comment with questions: ...
4
votes
1answer
96 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
115 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
121 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
67 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: ...

1
2 3 4 5
13