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
234 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
2k 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
141 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
88 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
999 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: ...
8
votes
1answer
483 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
631 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
77 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)....
2
votes
0answers
71 views

DOS header parser in Rust

Looking for feedback mostly on the from() and printf() implementations but I included everything for context. Please do not ...
7
votes
2answers
857 views

Fahrenheit and Celsius converter in Rust

I made a program that converts between Celsius and Fahrenheit. Is there any way that I could make this code more efficient and cleaner? ...
3
votes
1answer
265 views

Merge two sorted lists in Rust

I wrote the following code to merge two sorted lists. Is there a way I can improve it? Possible ideas (not sure how to implement them): Remove code duplication (setting the returning list node and ...
6
votes
1answer
175 views

Implementing a doubly linked list with smart pointers

I've been learning Rust for the past few days and I just passed the "Smart Pointers" chapter. To check what I've learned I've decided to implement a doubly linked list. My question is, is this ...
2
votes
1answer
115 views

Small stack based language in Rust

I made a small stack-oriented language in Rust. It tries to run anything it is given. To elaborate: Division by zero gives zero. If there is nothing on the stack and a request is made that involves ...
1
vote
1answer
90 views

Convert a type u16 number to a matrix (Vec<Vec<u8>> or array) of 4 x 4

I am a Rust newbie and I am not familiar with all the iterator options. This is what I have so far. How can I make this better or at least avoid collecting twice into a Vec? ...
3
votes
1answer
491 views

Rust Task Queue

The purpose of this program is to have one thread (main thread) working on I/O reading lines from a file and feeding it to a pool of worker threads whose job is to perform some processing on each line ...
2
votes
0answers
417 views

A multithreaded, growable vector with immutable elements, which has wait-free reads

I wrote a small vector with a few lines of unsafe Rust. The idea is to have a vector, which can be read from simultaneously, but it needs the ability to grow. To realize that, the storage is ...
3
votes
1answer
78 views

Temperature converter in Rust with input error handling

I started learning Rust a few hours ago with the Rust Book (2018 edition) and as part of one of the exercises decided to make a temperature converter. I wanted to make sure it handled all inputs ...
2
votes
0answers
658 views

Rust web server example with GraphQL, Rocket and Postgres

I'm very new to Rust and have tried to write a simple graphQL server with Rust and Postgres. It works, but I have not idea about what's good and what's bad here. I would love someone experimented to ...
3
votes
2answers
354 views

Sieve of Eratosthenes in Rust

This is a relatively simple implementation of the Sieve of Eratosthenes in Rust. The main objective is to find the \$n\$th prime quickly when \$n\$ might grow to huge numbers. ...
5
votes
2answers
367 views

Beginner Rust text adventure

I've been trying to pick up some Rust experience and decided to try and make a text adventure game. I'd like some feedback on potential bad practice and non-Rust-style code I may have used. I'm moving ...
7
votes
1answer
1k views

Recursive Fibonacci in Rust with memoization

I'm trying to come up with an "elegant" way of calculating Fibonacci for number in Rust, using recursion and memoization (self-imposed requirements). This is what I have so far: ...
7
votes
1answer
194 views

Frequency Analysis & Chi-Squared Test

Following up on my implementation of Cryptopals Challenge 1, this is my solution to Challenge 3. Single-byte XOR cipher The hex encoded string: ...
5
votes
1answer
47 views

CLI helper in Rust

This is my first hands-on experience with Rust. The program actually works and I really like how it functions. I'm just very interested in what code improvements I could do. I wrote an application in ...
4
votes
1answer
925 views

Doubly linked list in Rust

I have just started learning Rust, and in order to try to get the hang of references, ownership and mutability, I have attempted to make a doubly linked list. It now compiles, and the ...
2
votes
1answer
79 views

Crontab datetime field pattern parser in Rust

@angus on Unix.SE implemented a tool in C to list upcoming cron jobs in response to a question. I've re-implemented the basic functionality (showing only the next cron job) in Rust, using ...
2
votes
1answer
395 views

Convert hex to base64 (Cryptopals challenge 1)

I've been spending some time learning Rust and I came across the Cryptopals Challenges. This is my implementation of challenge 1 Convert hex to base64 The string: ...
4
votes
0answers
173 views

Collatz fractal in Rust

Among the many fractals, there is Collatz Fractal based on a complex extension of: $$f(x) = \left\{ \begin{array}{ll} \frac{x}{2} \space \text{if even} \\ 3x + 1 \space \text{if odd} \end{array} \...
8
votes
2answers
240 views

Rust Echo Command Implementation

I'm just starting out in Rust and I find the concept of ownership confusing so I wrote an implementation of the echo command. I would like to know if I could have ...
3
votes
0answers
77 views

static macro-based State Machine implementation

While learning Rust for the past couple of weeks, I set out to use the type-system to build a static State Machine implementation in Rust. The goals: program in idiomatic Rust no runtime overhead ...
4
votes
0answers
90 views

Bisection and Newton's method for finding a root of an equation

In an attempt to learn Rust, I've written up implementations of the bisection method and Newton's method for finding roots of an equation. Both methods come in two variants: the first one searches for ...
7
votes
0answers
136 views

Metropolis Monte Carlo Sampler in Rust

the following is an implementation of the standard Metropolis Hastings Monte Carlo sampler. You can read more about it here. At the end I am going to give you a link to the Rust playground, so you ...
3
votes
2answers
1k views

Image resizing in Rust

Are there Rust features I could apply to optimize for simple test of a JPEG or PNG resized from 2000 x 2000 pixels to 150 x 150 pixels? ...
6
votes
1answer
892 views

Dijkstra's algorithm in Rust

I'd love to get feedback on my first go at Dijkstra's algorithm in Rust: ...
5
votes
1answer
143 views

Simple interpreter written in Rust

I'd like to improve how ownership is handled within a simple interpreter written in Rust. The interpreter takes simple calculator like expressions and returns either a string of the AST or a number ...
5
votes
1answer
1k views

Convert string of hex into vector of bytes

I want to write a function that gets a string of hex numbers (two hex numbers represent a u8 value) then returns a vector of u8 ...
4
votes
1answer
420 views

A simple implementation of the Unix find command written in Rust

I'm a C++ developer trying to learn Rust for fun and XP. I decided to implement some of the Unix tools for practice. Below is a simplified implementation of the ...
4
votes
1answer
106 views

Finding Anagrams in Rust

I have written this program to find anagrams in a "pile" of letters (it'd be an effective way to cheat at Scrabble...) Run it like anagram abcedeede to get a list ...
7
votes
1answer
174 views

Library for managing sub-byte named bitfields

When writing custom network serialization in Rust, I've come across a use case for storing and retrieving values in bitfields smaller than the u8 available in Rust. ...
4
votes
0answers
94 views

Drawing the Mandelbrot with multiple threads in rust

The code below draws the mandelbrot set for { z | z∈ ℂ, -2.2 ≤ Re(z) ≤ 0.6, -1.4 ≤ Im(z) ≤ 1.4} into a 300×300px png image. For each pixel, if the sequence {zi} is found to ...
6
votes
2answers
878 views

The Ducci Sequence

I wrote the following Rust code to solve this task on /r/DailyProgrammer. Given an n-tuple of numbers as input, the Ducci Sequence is formed by taking the absolute difference of the difference ...
5
votes
0answers
269 views

HashMap exercise, Rust book Ch.8

I'm learning Rust by learning the Rust programming language book. I'm now implementing the solution for the third challenge. Using a hash map and vectors, create a text interface to allow a user to ...
3
votes
0answers
170 views

A tree command written in Rust - Error Handling

I am trying to learn Rust as my third main language (Coming from Java/Kotlin and Javascript/Node). For that purpose I reimplemented the Linux tree command. Not ...
4
votes
0answers
645 views

Finite Automata stub in Rust

I wrote a finite automata implementation in C years ago. C's access to mutable, unsafe, raw pointers made it quite simple for me to link/relink the states of a finite automata. I read the official ...
7
votes
1answer
93 views

Configuration file parser

https://github.com/pixlark/vars-parser ...
4
votes
1answer
139 views

Karatsuba multiplication in Rust

This is an implementation of the Karatsuba algorithm for multiplication: ...
10
votes
2answers
194 views

Laptop battery level monitor for Linux

I come from a C background and am trying to learn Rust. I wrote my first Rust program, to check the battery level on my laptop and warn me if it's low/critical. It works fine, but I wrote it in a ...
2
votes
0answers
93 views

Finding n-distance neighbors in a hexagonal grid

In a grid of hexagons, we often want to find the neighbors of a cell with distance n. In the image below we have a rhombus-shaped grid of hexagons with an axial ...
2
votes
1answer
110 views

Check whether an integer's leftmost bits are ones in Rust

I'm trying to validate if an integer represents a valid IPv6 mask, which boils down to checking if all the left-most bits of an u128 are 1s, and all the right-most bits are 0s. For instance: ...
2
votes
0answers
85 views

Largest Rectangle in Histogram in Rust

Whilst learning Rust I am solving different algorithm problems. Below is a solution to largest rectangle in histogram. Algorithm is well described here: Although code below does the job it is very ...
7
votes
0answers
340 views

IPv6 parsing in rust

Here is code to parse an IPv6 address. An IPv6 address is 128 bits long. When represented in its printable form, its hextets (1 hextet == 16 bits) are represented as hexadecimal numbers, and are ...

1
3 4
5
6 7
10