Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
0answers
10 views

Calling functions in the implementation of a trait function

Consider the following example: I have a trait Foo with a function foo() and an associated type ...
1
vote
0answers
18 views

A syslog to Azure Log Analytics forwarder

I am using this code to forward my syslog logs (converted to json using syslog-ng) to Azure Log Analytics on an ARM board (since there is no official client for ARM)...
9
votes
2answers
1k views

Circular FIFO Buffer

I was bored the other day and got to wondering how I would implement a circular FIFO buffer in Rust. My goal was to create an implementation I could use on a bare metal microcontroller. This means no ...
0
votes
1answer
49 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 ...
3
votes
1answer
41 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
57 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
68 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 ...
2
votes
2answers
134 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: ...
6
votes
1answer
71 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-...
4
votes
1answer
98 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
50 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
40 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 ...
5
votes
2answers
572 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
76 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 ...
5
votes
1answer
68 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
75 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
46 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? ...
1
vote
1answer
73 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
333 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
61 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 ...
1
vote
0answers
108 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
82 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
176 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 ...
5
votes
1answer
131 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: ...
6
votes
1answer
95 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: ...
4
votes
1answer
34 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 ...
3
votes
1answer
136 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
63 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
130 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: ...
3
votes
0answers
93 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} \...
5
votes
2answers
70 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
45 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
41 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 ...
6
votes
0answers
59 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 ...
2
votes
2answers
175 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? ...
4
votes
1answer
135 views

Dijkstra's algorithm in Rust

I'd love to get feedback on my first go at Dijkstra's algorithm in Rust: ...
3
votes
1answer
74 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 ...
3
votes
1answer
167 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
80 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 ...
3
votes
1answer
60 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
83 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
43 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
207 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
94 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
49 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
605 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
55 views

Configuration file parser

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

Karatsuba multiplication in Rust

This is an implementation of the Karatsuba algorithm for multiplication: ...
9
votes
2answers
154 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
53 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 ...