r/learnrust 1h ago

Review this pure backend project

Upvotes

I’m thinking of creating a complete authentication service provider backend in Rust, which would include - OTP, magic links, email-password, SSO and a lot more.

Basically something like AuthJS or Appwrite (only the authentication service of theirs), with proper failure handling, spike handling, backpressure and everything that such a system requires at scale.

This would help me learn async Rust in detail (I’ve never done it) and system design for such a system.

This is not a new idea, but I don’t mind if it teaches me stuff.

Review this project idea.
Open to feedbacks/roasts.


r/learnrust 21h ago

Am I Learning, Am I Incorrect or Am I Missing a Point?

10 Upvotes

So a video came by my feed here he walks through how to design a more reliable and user-friendly progress bar for Rust by taking inspiration from Python's tqdm library. In order to implement with_delimiters to bounded iters only he went and used state design pattern. I was like "Ok cool cool" at first because of course I'm learning. But then I think i noticed some redundancy in the code. In the implementation of width_delimiters, the generic type is already bounded by ExactSizeIterator. So I went and copied the code and tried to remove the state design implementation. I also removed the 'with_bounds' method because iters is already bounded or not. My final code below shows that with_delimiters method only work with bounded iterator

My Final Code

``` use std::thread::sleep; use std::time::Duration;

pub struct Progress<I> { iter: I, i: usize, bound: Option<usize>, delims: (char, char), }

impl<I> Progress<I> where I: Iterator, { pub fn new(iter: I) -> Self { Self { iter, i: 0, bound: None, delims: ('[', ']'), } } }

impl<I> Iterator for Progress<I> where I: Iterator, { type Item = I::Item;

fn next(&mut self) -> Option<Self::Item> {
    let item = self.iter.next()?;

    if let Some(bound) = self.bound {
        println!(
            "{}{}{}{}",
            self.delims.0,
            "*".repeat(self.i),
            " ".repeat(bound - (self.i + 3 - 2)),
            self.delims.1,
        );
    } else {
        println!("{}", "*".repeat(self.i));
    }

    self.i += 1;
    Some(item)
}

}

impl<I: ExactSizeIterator> Progress<I> { pub fn with_delimiters(mut self, left: char, right: char) -> Self { self.bound = Some(self.iter.len()); self.delims.0 = left; self.delims.1 = right; self } }

trait ProgressIteratorExt: Sized { fn progress(self) -> Progress<Self>; }

impl<I: Iterator> ProgressIteratorExt for I { fn progress(self) -> Progress<I> { Progress::new(self) } }

fn expensive_function() { sleep(Duration::from_millis(500)); }

fn main() { // error: unbounded iter for _item in (0..).progress().with_delimiters('{', '}') { expensive_function(); } }

```


r/learnrust 10h ago

Got any Idea?

Thumbnail
1 Upvotes

r/learnrust 14h ago

Good architecture for Rust as backend (tauri 2)

2 Upvotes

TL;DR: What would be a good architecture for a Rust backend in the Tauri 2 framework with 3 user-facing interfaces (GUI, MCP, CLI) and multiple external resources (Docker, Git, SQLite, file system, remote data storage, ...) that does almost everything concurrently with tokio?

Hi. I'm currently building a tool that aims to help Business Central (BC - ERP system by Microsoft) developers and vibe coders operate more efficiently. The tool will make managing Docker containers, repositories, dependencies, and so on way easier. In addition to the GUI (Vue/Vite/Element Plus), I also want to provide a CLI and MCP. To make it even easier for the user, I plan on implementing a project-based system where you can set everything up for a customer, and if something changes (e.g. the BC version), the user updates the config and the program takes care of the rest.

Obviously, there are quite a few interfaces I need to cater to. For one, there are three different front-facing ones. And then, on the backend, there is Docker (bollard), Git (git2), SQLite (Tauri SQL plugin), the file system, remote resources, and so much more. Of course, all of that is built for concurrency.

I am in the very early stages of development and have implemented the basis for the Docker capabilities (backend and GUI) and started on Git. Of course, this already involves a lot of file system and remote resource (http, downloads, ...) interaction. I have yet to begin with any of the SQL, CLI, or MCP stuff. But I already notice some challenges and therefore want to apply a design pattern that allows me to implement all of these features without it becoming a complete clusterduck.

I tried Hexagonal Architecture from Alistair Cockburn in a Python project once and could imagine that it fits Rust as a language quite well. On the other hand, while thinking about implementing it, I already encountered heaps of challenges (which does not mean that this can't be the answer).

One thing I want to mention is that I do not have a lot of experience with Rust. I read the book a second time, more focused this time, over the last two months or so, and this project started as a practice project while I was in the middle of the book. Since I primarily focus on learning Rust right now, I did not dive all that deeply into the tauri framework itself, which I will definitely do soon.

But until then: What would be a good architecture to implement before moving on with new features? If you have the time I would be glad to read about your reasons and maybe even experience with it.


r/learnrust 1d ago

How to convert a &mut i32 to integer?

18 Upvotes

Hello everyone. I am following the rust programming language book and I've just now finished chapter 8. Just doing some of the exercises suggested at the end.

I have written this simple function to find the mode from a given list of numbers:

fn mode(list: &mut Vec<i32>){


    let mut items=HashMap::new();


    for i in list{
        let count = items.entry(i).or_insert(0);
        *count += 1;
    }
    let mut largest_value = -5; // initialize to a very small number
    let mut most_frequent_key = 0;
    for (key, value) in items{
        if value > largest_value{
           largest_value = value;
           most_frequent_key = key;
        }
    }


    println!("mode: {most_frequent_key}");
    println!("{:#?}",items);
    
}

In the last step of the second for loop, I want the most_frequent_key variable to accept my key variable but I understand that the former is expecting an integer and key is a mutable reference to an i32 value. So I don't know what to do here.

Previously, through some trial and error I did figure out that I could use the dereferencing(*) operator on key to accomplish that but then the compiler tells me that I am apparently "moving" the items value and hence can't use use it again in the println!() statement in the last step of the function.


r/learnrust 1d ago

Build a Scientific Calculator in Rust - Understanding Variables and Types

Thumbnail blog.sheerluck.dev
6 Upvotes

r/learnrust 2d ago

what i’ve learned so far

0 Upvotes

wrote my first article on X detailing about little things I learned apart from the Rust book’s content while reading through chapters 1-3 this past week.

you can find it here: https://x.com/zepredos/status/2094169365424013351?s=20

i’d appreciate any feedback you have and would love to learn more Rust!!


r/learnrust 3d ago

I built a local vector database for Flutter powered by Rust and HNSW graphs (Waffle-DB)

Thumbnail github.com
1 Upvotes

Hey everyone,

Most local storage options in Flutter like SQLite or Hive are built for scalar data and fall apart when you need fast vector similarity search for on device AI, semantic search, or high dimensional embeddings

I built waffle_db, an embedded vector database for Flutter and dart apps by Rust. It uses HNSW graphs for approximate nearest neighbours, sledge for persistence, and Rayon for parallel batch ingestion.

How it works under the hood:

Off thread Rust execution: Graph indexing, cosine distance math, and persistence run in Rust via FFI, keeping the Flutter UI thread completely free of jitter.

Native HNSW graphs: Provides k-NN retrieval even across large vector spaces instead of linear brute-force scans.

Memory efficiency: Uses zero-copy typed buffer views (Float32List) across the FFI bridge to minimize heap allocations.

Metadata and Namespaces: Stores arbitrary payload metadata alongside vectors and supports logical collections (WaffleCollection) with automatic ID namespacing.

Prebtuned profiles: Comes with configurations out of the box like mobileProfile (quantization enabled, lightweight graph parameters), serverProfile, readHeavyProfile,writeHeavyProfile

Pub: https://pub.dev/packages/waffle_db

GitHub: https://github.com/MostafaSensei106/Waffle-DB

If you are building local RAG pipelines, on device semantic search, or AI features in Flutter, check it out and let me know your thoughts or feedback.


r/learnrust 4d ago

What security measures would you recommend for somebody relatively new to rust working on one egui project, when a VM is a non-starter. (noob, be kind!)

11 Upvotes

TLDR: have been a bit complacent about security, but need some advice given limitations in hardware and experience. just need some pointers to focus on.

the recent arrayref saga spooked me. i actually avoided pulling the dodgy version because i tend to wait a while before upgrading my main dependencies. i'm still worried though and would like to take some more measures, but i really don't have any experience with containers.

VMs are a non-starter because i have 5.6GB of ram, and given rust analyzer takes 2.5GB i'd be cutting it really fine.

i've been reading about containers but there's so much information and i can't make sense of it.

my current project is a launcher in egui, similar to rofi or fuzzel. this app reads the system and user folders for fonts and icons and also reads the .config folder. from what i can gather granting read-only access to these is fairly simple. what i'm less sure of is neovim, which will need to run rust analyzer, and also testing the app, which will need access to god only knows (if by "god" i mean somebody maybe a little more savvy than me).

given the way i work, i'm not sure i even need to take measures other than running cargo audit regularly. it's not like i'm working on several projects, each with their own dependency tree. i'd just like to get a system i can feel mostly confident in so i can get back at it. i've really taken to this and am kinda sad to stall like this.

some info that might be important
OS: endeavourOS
DE: hyprland/labwc
ram: 8GB but 5.66 after the integrated GPU takes its cut.
cpu: AMD ryzen 5 3500U @ 2.10GHz
been learning rust about a year.
prev knowledge: a bit of experience in python and lua and a tiny bit of javascript.

also sorry for the long panicky post. i write like i code.


r/learnrust 3d ago

Looking for Rust project ideas to improve my skills

Thumbnail
1 Upvotes

r/learnrust 3d ago

How to learn rust as a python guy?

Thumbnail
1 Upvotes

r/learnrust 4d ago

I wrote an async port scanner in Rust (my first "real" Rust project)

10 Upvotes

Learning Rust and decided to build a port scanner to understand async/await.

Features:

  • Async TCP connect with tokio
  • Service banner grabbing
  • JSON output for scripting
  • ~10k ports/second on localhost

Still learning, so code review welcome. How it works:

  • CLI (clap) takes the host, port range, timeout, and how many ports to scan at once
  • It runs N ports at a time so it never opens thousands of connections at once. --sync does one at a time
  • Each port gets a TCP connect with a timeout. Connects = open. Fails = closed or filtered, I can't tell which
  • On open ports it sends something and reads the reply — a GET for HTTP ports, PING for Redis, nothing for stuff like SSH that talks first. No reply is fine, the port is still open
  • Open ports print as they're found and go to results.txt at the end

Feel free to use, contribue and open issues!

https://github.com/DaviAlcanfor/anubis


r/learnrust 6d ago

Audio learning

24 Upvotes

Hi. I visit the gym every other day roughly, is there an audio only podcast or series I could listen to for learning Rust (e.g. not for someone who already knows the language well) ?

TIA


r/learnrust 6d ago

Built a tiny Unix like shell

9 Upvotes

So I’ve been learning Rust for a while and I have always admired how the most common technologies/tools are built, so I always try to build things from scratch to understand how it works from the inside - a shell was one such project.

Here, I present Wish - a simple shell built to learn the internals of a full-blown Unix shells.

I got to learn a lot of new things while implementing wish - file handles, command spawning, shell-builtins, etc.

What it does?
Most of your day-to-day commands would work just fine, including piped commands.
Having said that, this project has rough edges as this was meant to be educational; and that’s the point, it is convenient and simple - type `cargo run` and you’re good to test out the shell.

Try it out, extend it, provide feedback.

Source code: https://github.com/Abhijeet-Gautam5702/wish


r/learnrust 8d ago

Bad performance when writing rust in Zed

17 Upvotes

Hi everyone, I am a second year SE student and a total noob at rust, so I apologize if this question sounds stupid.

I am currently working on a personal project, and am using Zed to write the backend in rust. I don't know if my workflow/configuration is just all messed up, but every time I run cargo check it just eats up all my cpu usage. It got to the point where I had to turn of the checkOnSave setting because it just totally slowed down my laptop. But that's also annoying because I have to run cargo check just to catch stupid errors like a the value 8080 not being in the range of a u8 (like I said, I'm a noob).

My laptop is a bit old, with an Intel i7-1165G7 with 16gb ram, integrated graphics. I do have a 4k and 2k monitor both connected, so I know that could be heavy on the cpu as well.

This is my configuration for the lsp as well in case I did something stupid there.

I don't know what other info I need to provide so for anyone trying to help let me know what you need to see and I'll edit the post. Thanks in advance!


r/learnrust 9d ago

Is this something the new borrow checker will fix?

12 Upvotes

I have two questions about this code: Will the new borrow checker (currently in nightly I believe) fix this case and is there a good workaround in the mean time?

It's annoying because when I put this code inline inside the function that owns the Arc, it works. It only breaks when I try to extract this function.

I'm pretty sure this should be memory safe. In the case where Arc::get_mut returns None, I'm not using the borrow anymore. I'm aware Arc::make_mut exists but it doesn't do exactly what I want. In the uncommon case where another thread holds a reference, I don't want to pay the cost of cloning the existing Vec. I just need a new one.

fn get_mut_or_new_vec(materials: &mut Arc<Vec<Material>>, capacity: usize) -> &mut Vec<Material> {
    match Arc::get_mut(materials) {
        Some(v) => {
            v.clear();
            v.reserve(capacity);
            v
        }
        None => {
            std::mem::replace(materials, Arc::new(Vec::with_capacity(capacity)));
            Arc::get_mut(materials).unwrap()
        }
    }
}

error[E0499]: cannot borrow `*materials` as mutable more than once at a time
  --> src/main.rs:470:31
   |
462 |   fn get_mut_or_new_vec(materials: &mut Arc<Vec<Material>>, capacity: usize) -> &mut Vec<Material> {
   |                                    - let's call the lifetime of this reference `'1`
463 |       match Arc::get_mut(materials) {
   |       -                  --------- first mutable borrow occurs here
   |  _____|
   | |
464 | |         Some(v) => {
465 | |             v.clear();
466 | |             v.reserve(capacity);
...   |
470 | |             std::mem::replace(materials, Arc::new(Vec::with_capacity(capacity)));
   | |                               ^^^^^^^^^ second mutable borrow occurs here
...   |
473 | |     }
   | |_____- returning this value requires that `*materials` is borrowed for `'1`

error[E0499]: cannot borrow `*materials` as mutable more than once at a time
  --> src/main.rs:471:26
   |
462 |   fn get_mut_or_new_vec(materials: &mut Arc<Vec<Material>>, capacity: usize) -> &mut Vec<Material> {
   |                                    - let's call the lifetime of this reference `'1`
463 |       match Arc::get_mut(materials) {
   |       -                  --------- first mutable borrow occurs here
   |  _____|
   | |
464 | |         Some(v) => {
465 | |             v.clear();
466 | |             v.reserve(capacity);
...   |
471 | |             Arc::get_mut(materials).unwrap()
   | |                          ^^^^^^^^^ second mutable borrow occurs here
472 | |         }
473 | |     }
   | |_____- returning this value requires that `*materials` is borrowed for `'1`

For more information about this error, try `rustc --explain E0499`.

r/learnrust 10d ago

What got you to try programming in rust than other programming language?

34 Upvotes

r/learnrust 10d ago

Help me prepare for a Rust interview

8 Upvotes

r/learnrust 10d ago

My first project after reading The Rust Programming Language

16 Upvotes

Hello My Name is YASSINE, and this is my first project after reading The Rust Programming Language :

ZlijaNote CLI

This is a simple, educational Rust CLI for managing notes in JSON. Built to practice clap, serde, and custom error handling.

I will really appreciate your feedback. Thanks!


r/learnrust 10d ago

Built getarustjob.com, a job board dedicated exclusively to Rust roles

27 Upvotes

Hey everyone,

I built getarustjob.com, a job board focused exclusively on Rust engineering roles.

I’ve already posted a batch of active Rust jobs on the site, so feel free to check them out if you're currently looking.

I also put together a weekly newsletter that sends a curated list of vetted Rust openings every Monday: getarustjob.com/newsletter.


r/learnrust 10d ago

A structural text editor for searching and rewriting byte ranges

0 Upvotes

r/learnrust 10d ago

Lets get rusty opinion

7 Upvotes

Hello!

I’d love to hear some opinions from people who have taken the Let’s Get Rusty course/bootcamp.
I’ve been learning Rust on my own for a while, but I’ve realized that I tend to learn much better with some structure, guidance, and a bit of peer pressure/accountability to keep me motivated.

For anyone who has done the course: Was it worth it? How was the teaching, workload, community, and overall experience? Would you recommend it to someone who already has some programming experience but is still getting comfortable with Rust?

Any feedback would be greatly appreciated!


r/learnrust 11d ago

Im full stack dev ( TypeScript ), I want to learn rust because it seems interesting

28 Upvotes

Beyond my professional experience with the TypeScript and Python. I am hobbyist in Robotics and Dev Tools.

I want to know what advantage does Rust have in it's own domain, How can I start learning it?

TIA


r/learnrust 11d ago

Increased GeoLog's location sorting using Rust

Thumbnail
1 Upvotes

r/learnrust 11d ago

Out-of-bounds array access: a practical Rust vs C++ comparison

Thumbnail techfortalk.co.uk
3 Upvotes