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

Calculating square roots using binary search

I'm trying to find the square root of a number (num) using binary search in Rust. I'm new to Rust, but I've done quite a bit of programming in other languages, ...
user avatar
  • 111
0 votes
0 answers
8 views

Group list of objects into smallest possible number of sublists without exceeding maximum sum

I have converted my Java answer from this question into Rust. As I am new to Rust, I would like to know about what I could improve in my code. Mostly I would guess that I could improve on borrowing, ...
user avatar
2 votes
0 answers
30 views

Algorithm for solving `subsequence with highest win rate`

Problem Inputs: 1. min length of subsequence 2. binary sequence outputs: 1. starting index of sequence 2. subsequence length The task is to find a subsequence ...
user avatar
1 vote
0 answers
25 views

Cleanly modifying values in hashmap for a k-sum challenge

Just started learning Rust and here's a program that has caused me some agony to implement in Rust. This is very easy to implement in C++, but Rust's borrow checker is causing all sorts of trouble. My ...
user avatar
  • 33
0 votes
0 answers
27 views

I am building a container of differently typed variables with names for easy parsing and usage in Rust

I am new to Rust and trying to learn more about it. I want to have some kind of container that can store parameters (variables, values, constants) of varying types together with a name. This container ...
user avatar
  • 101
0 votes
0 answers
21 views

Sensibly using fastq crate to modify fastq files

I'm learning Rust, and I have a simple program that I hope to use as a learning exercise. My goal here is to get a better idea of the proper way of doing things. I'm trying to use the fastq crate to ...
user avatar
  • 1
2 votes
2 answers
60 views

Partitioning a list so that even numbers appear before odd numbers

I started learning Rust today and figured, I could ask for some code reviews to learn to make my code idiomatic and learn about its code generation. I spend my days writing highly optimized Java and C+...
user avatar
  • 33
1 vote
2 answers
48 views

Generate vertices and normals for a flat shaded cylinder

I would like to generate list of vertices and normals (with the correct indices) for rendering a cylinder barrel (I ommited the end caps for brevity). The normals should not be interpolated (flat ...
user avatar
1 vote
1 answer
83 views

Extremely simple virtual machine in Rust

I wrote a very simple VM to get a bit more familiar with Rust. The VM architecture was not the focus, so that I think that can safely ignored. Is my code idiomatic and clean? I felt that I was very ...
user avatar
  • 269
6 votes
1 answer
62 views

Tic Tac Toe Module in Rust: Implementing "new"

Intro In order to get familiar with and improve my Rust skills I coded Tic-Tac-Toe. I want to write good Rust code, any feedback regarding why my code isn't in a Rust style or improvements that could ...
user avatar
8 votes
2 answers
581 views

Multithreaded bogosort in Rust

For some quick context, I'm fairly new to Rust and decided to give myself a difficult-but-attainable task of implementing a sorting algorithm. I chose bogosort (or stupid-sort, shuffle-sort, whatever ...
user avatar
1 vote
0 answers
17 views

Wrap an ssh2 connection neatly and pass commands

I want to structure this better but don't think I'm handling results well. I'm used to python and I think my flow is way off. Is this bad design? Should my results be Result<String, Error>? I'm ...
user avatar
1 vote
1 answer
75 views

The Rust Programming Language book: Company HashMap exercise (Ch. 8)

This is my solution to the third exercise (and last) at the end of chapter 8 of The Rust Programming Language book (https://doc.rust-lang.org/book/ch08-03-hash-maps.html#summary). There are only 3 ...
user avatar
  • 11
3 votes
0 answers
37 views

Rust book chapter 8.03- Text interface to add employees

https://doc.rust-lang.org/book/ch08-03-hash-maps.html 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 ...
user avatar
1 vote
0 answers
45 views

Rust: nested values within struct

I want to understand how to properly nest key/pair values within a struct. My use case is to create a type to return serialized JSON on my API responses. I'm using rocket, this is my general setup: <...
user avatar
1 vote
0 answers
27 views

Console Tic-Tac-Toe game in Rust

While having experience with other languages I only recently started learning Rust and I was hoping to get some feedback on my little beginner project, especially regarding style (stuff like too many ...
user avatar
2 votes
0 answers
30 views

Reverse Words in a String, while preserving the order of words - rustlang

Source: https://leetcode.com/problems/reverse-words-in-a-string-iii/ I want to know What better could I do, regarding syntax and idioms What better could I do, regarding performance ...
user avatar
2 votes
1 answer
63 views

A Rust beginner's Hangman game

I have been learning Rust for a few days (This is my third) now, and I've really fallen in love with the language, this is my first real project, Hangman. I was wondering what I could do better / what ...
user avatar
  • 43
6 votes
0 answers
56 views

Chapter 8 Challenge: Add employee names to a department

The boring but exciting challenge: Using a HashMap and HashSet, create a text interface to allow a user to add employee names ...
user avatar
  • 61
2 votes
0 answers
72 views

Mastermind in Rust

To learn Rust I coded a clone of Mastermind. Mastermind is a 2-player game, where a master chooses a combination of 4 pegs which are of 6 different colors (For example : Red Yellow Blue Red) The other ...
user avatar
1 vote
1 answer
69 views

Continuous knapsack problem in Rust

Background The continuous knapsack problem is the following linear program: $$ \begin{align} \text{maximize} \quad & f(x) = \sum_{i=1}^n u_i x_i \\ \text{subject to} \quad & \...
user avatar
  • 195
2 votes
0 answers
54 views

Rust app to download, process, and upload files to S3

I've written a small server app which grabs a token from another server, downloads JSON, then downloads files referenced in that JSON, processes them with a CLI ...
user avatar
  • 121
0 votes
0 answers
73 views

Calculate the largest palindrome under x-digits multiplication

Here is my Rust program: ...
user avatar
  • 11
7 votes
2 answers
449 views

Median cut algorithm

I have implemented a simple version of the median cut algorithm. It takes a vector of Color structs representing pixel in an image. I also use the ...
user avatar
2 votes
0 answers
96 views

CSV file aggregator (appender) CLI

My goal is to write a CLI utility that aggregate (appends) many CSV files in a lightweight and performant (my use-case involves output files in the 10s of GBs) manner. Specifically, the utility ...
user avatar
  • 223
0 votes
1 answer
35 views

Rust wrapper around Win32 Fiber

So this one was quite rough to implement. I needed to pass an FnOnce to a foreign function through a c_void which requires ...
user avatar
0 votes
1 answer
51 views

Image scraper using Dependecy Injection in Rust with generics

I'm writing a scraper that downloads images from a given subreddit. I'm new to Rust, and in the majority of my previous projects I was using C++ or Java, where it's easy to do Dependency Injection. I ...
user avatar
0 votes
1 answer
54 views

Generically calculate powers of two below a number

The following function is an attempt to generate powers of two below the input number max. So powers_of_two_below(15u8, u8::BITS)...
user avatar
  • 711
6 votes
1 answer
143 views

Rust CLI for playing Wordle

I wrote the following CLI for playing the popular word game - Wordle. Wordle is a word game in which players are trying to guess a 5 letter word. Each turn they guess one 5 letter word, and for each ...
user avatar
  • 163
3 votes
1 answer
63 views

Minimum Spanning Tree in Rust

As a project I have worked on implementing and benchmarking two different minimum spanning tree algorithms in rust. My main concern is adhering to good style and not programming any glaring ...
user avatar
  • 171
0 votes
0 answers
18 views

A Rust CLI app that manages Azure resource

This is my first Rust app that I've created after reading the wonderful book. I think it doesn't make sense to copy the entire source code in here, here's the link to GitHub. If I should copy the ...
user avatar
  • 155
6 votes
1 answer
91 views

Lexer for a Scheme-like language in rust

I was/am working on an interpreter for a scheme-like language. Just some time back I shifted my implementation from C++ to Rust, which I just started learning. I know there are parser libraries like ...
user avatar
1 vote
0 answers
49 views

Lock-Free Single Reader/Single Writer Lamport Queue

I've created a lock-free lamport queue in rust. My code should be clear enough that you won't need to understand a lamport queue before reading it, but if you'd like a reference, this paper give a ...
user avatar
2 votes
2 answers
116 views

Rust Cacher implementation (chapter 13 of the Book)

In https://doc.rust-lang.org/book/ch13-01-closures.html the author recommended to try to implement Cacher that: Stores values in a ...
user avatar
  • 155
1 vote
1 answer
239 views

How do I get the unique list of values from a hashmap in rust?

I have the following code which finds all the unique values from a hashmap of String to Vec. I cobbled it together (eventually as I was getting various borrow errors along the way), but it looks a ...
user avatar
5 votes
1 answer
239 views

Rust program to one hot encode genetic sequences from .fa files

I wanted to write some code which reads in a FASTA file and one hot encodes the sequence which is consequentially saved to a file. A FASTA file is a text based file format commonly used in ...
user avatar
5 votes
1 answer
150 views

Rust CLI tool to synchronize files to S3

Learning Rust, I've written a small CLI tool which will Fetch the existing data in S3 Iterate through local folders Upload the files which don't exist in S3 I'd be keen to hear anything I might have ...
user avatar
5 votes
1 answer
105 views

Processing binary data in Rust

I have binary files that need to be efficiently processed. The first 8 bytes correspond to metadata, and all the rest is data. From the first 8 bytes I need the last 4 bytes to determine how to ...
user avatar
  • 384
1 vote
1 answer
57 views

Floating point addition algorithm

I made a function in Rust to add two floating point numbers (f32s) together using only their bit representation and integer operations. I have tested it for a quite ...
user avatar
3 votes
1 answer
64 views

Project Euler problem 11 in Rust: largest product of consecutive elements in a grid

I wrote the following Rust code for euler project problem 11. It works and a small test is included, but I am not very happy about the code. At first I wanted to chain together iterators for all the ...
user avatar
  • 188
3 votes
1 answer
88 views

2021 Advent of Code, Day 1 Part 2: Keeping error-handling simple while chaining iterators with Rust

This question is with respect to Day 1, Part 2 of the 2021 Advent Of Code challenge, which requires comparing values from a rolling window taken from integers streamed as input. This answer is correct,...
user avatar
2 votes
0 answers
190 views

Parallel Breadth First Traversal in Rust

Overview I have been writing my own graph API for Rust and one thorny problem I wished to tackle was a parallel breadth first traversal of the graph. The API itself will have different graph flavours, ...
user avatar
  • 171
1 vote
0 answers
78 views

Implementing a LinkedList in Rust

I have this LinkedList implementation for rust and it isn't quite what I am looking for. Ideally, it would be more like scala's implementation of List and be entirely immutable. This implementation ...
user avatar
2 votes
1 answer
51 views

Pig Latin terminal app in Rust

I've started learning Rust a few days ago. This is the Pig Latin exercise from the Rust Book. The code works as expected. I have commented the logic of the program in the code. My handling of ...
user avatar
  • 123
3 votes
2 answers
387 views

Rabbit Searching Problem in Rust

This is my Rust implementation of the rabbit searching algorithm I found yesterday in this video. The problem statement is as follows. There are 100 holes in a line. A rabbit is in one of the holes. ...
user avatar
  • 33
3 votes
1 answer
92 views

Idiomatic way to extract matches from rust Regex?

I'm learning rust and doing an exercise where to parse a particular SGML document. Each line in a document can be either an opening tag "" , a closing tag "" or a scalar: " ...
user avatar
3 votes
1 answer
98 views

Reading input in idiomatic Rust for Advent of Code Day 2

I'm trying to write idiomatic and fast Rust code by solving AoC challenges this year! :-) Link to AoC Day 2 problem The input format in this problem is a list of lines each containing one string token ...
user avatar
4 votes
1 answer
153 views

Advent of Code 2021: day 1

I am doing the Advent of Code challenge to learn Rust (obviously there may be spoilers if you still want to do the challenge). The instructions are too long to include verbatim so I will link them and ...
user avatar
1 vote
1 answer
44 views

Rust Pig Latin Translator - Idiomatic suggestions

This is the code I came up with for the Rust pig latin exercise. I am looking for suggestions on how to make it more idiomatic. I think working with iterators instead of chars and Strings would be a ...
user avatar
3 votes
1 answer
61 views

Building a trie from a vector of strings in Rust

I'm learning rust (coming from C++) and playing around with different small algorithms to understand the ownership & borrowing concepts better. Currently, I'm having difficulties finding the ...
user avatar

1
2 3 4 5
14