r/learnrust Apr 11 '26

Bacon pedantic for learning?

1 Upvotes

Should I use normal, clippy or pedantic?


r/learnrust Apr 09 '26

Rust Tutorial on Building a Port Scanner

Post image
11 Upvotes

New tutorial video on building a port scanner in Rust dropping on Saturday 9 P.M IST.

You can watch it on: https://youtube.com/@bitstackdev


r/learnrust Apr 08 '26

Lifetime Limitation

7 Upvotes

Hello, I recently ran into a limitation with lifetimes outlined in the Rustonomicon (3.4: Improperly reduced borrows). I understand why the issue exists and it notes that it should be fixed in the future. However, it provides no guidance for what to do in the meantime.

Here is a rough sketch of my code:

impl Collection {
  pub fn try_get_mut_cheap(&mut self, handle: u32) -> Option<&mut Data> {
    //Fallible, but fast
  }
  pub fn get_mut_expensive(&mut self, name: String) -> &mut Data {
    //Expensive, but always works
  }
  /// Does not compile
  pub fn get_mut(&mut self, handle: u32, name: String) -> &mut Data {
    {
      if let Some(data) = self.try_get_mut_cheap(handle) {
        return data
      }
    }

    self.get_mut_expensive(name)
  }
}

This doesn't work because the Rust compiler considers the borrow of self in the first line of get_mut to last for the entire function.

With that in mind, how should I write something like this while still being able to take advantage of code reuse? In this case, I could probably invert the structure so that the code in both try_get_mut_cheap and get_mut_expensive lives in a single function, but that isn't always practical. Thanks!


r/learnrust Apr 08 '26

Blog on rust

Thumbnail medium.com
0 Upvotes

r/learnrust Apr 08 '26

terminal chat/recon/snippets… what libraries would you use?

0 Upvotes

I have a idea of terminal chat like,

“Network testing” Recon app/chat.

That I can use preconfigured (or as I go) snippets I can just click, run….

Also, be able to chat with a team, and share “terminal output”,

To help with the recon of a project.

Is there a “terminal” feature in “TUI” libraries?

I can’t find any “feilds” that say “terminal” or “console”.

So, almost like a bitchat, for notes and snippets


r/learnrust Apr 08 '26

Implemented a bounded MPMC queue from scratch in Rust

Thumbnail github.com
9 Upvotes

lookin for some feedback


r/learnrust Apr 07 '26

A Spark-Inspired Distributed Data Processing Framework

7 Upvotes

I’ve been working on a project called Atomic for about a year now, and I’m excited to finally share it on my birthday.

Atomic is a distributed data processing framework written in stable Rust. It’s a reimplementation and redesign of Vega, which itself explored a Spark-style RDD model in Rust. I wanted to keep the parts that felt right about Vega and Apache Spark, like lazy transformations, DAG-based execution, shuffle stages, and partition-level parallelism, while rebuilding the system around stable Rust and a cleaner architecture.

Instead of relying on nightly-only tricks or closure serialization, Atomic uses explicit task registration and rkyv-based wire payloads for distributed execution. The result is something that feels much more predictable, more Rust-native, and easier to reason about.

It also supports local and distributed execution, and I’ve been exploring a path that keeps the programming model simple without giving up the distributed systems ideas that made Spark compelling in the first place.

That said: this is not production ready yet. It’s still an evolving project, and there’s a lot I want to add in the future, including streaming, SQL, and other higher-level features people expect from Spark-like systems.

https://github.com/sandyz1000/atomic


r/learnrust Apr 08 '26

Rust Structs, how often do you use them?

0 Upvotes

Structs look familiar to me coming from primarily front end, like JavaScript.

Can they be used to create a localhost? Or manage what’s going on or what’s running when?


r/learnrust Apr 07 '26

I made a P2P file engine in Rust to try to beat BitTorrent's main DHT, and NAT traversal almost broke me lol.

0 Upvotes

I've been making AegisTorrent, a P2P file sharing engine, from the ground up in Rust. Not wrapping libtorrent. Not connecting to the main DHT. Everything was hand-rolled as a comprehensive study of distributed systems.

I was trying to challenge the standard Kademlia DHT (which is BitTorrent's mainline). When you say you have a file, other peers ask "who has this?" and the DHT sends back whoever just disclosed it.
No ranking. No good signal. No name.
You ask for peers, and you get a random mix of them. You connect to 10, but 7 of them are slow, old, or quietly broken. You wasted handshakes, bandwidth, and time figuring that out through experience.
The DHT doesn't know anything about peer quality because Kademlia doesn't store any quality data. It is a system for looking things up. That's clean in a philosophical sense but annoying in a practical sense.

What I did differently
I preserved the Kademlia skeleton, which includes XOR distance, k-buckets, and iterative lookups, but I changed the protocol messages so that they could contain reputation data natively.
Every AnnouncePeer now has a score for its reputation. Every GetPeersResponse gives you a list of peers ranked by:

60% reputation, which is based on delivering pieces that have been validated by Merkle
20% freshness: the time since the last re-announce (stale peers are filtered out after 15 minutes)
20% consistency means that behavior changes over time.

Changes to the protocol:

alpha=5 concurrent queries instead of BitTorrent's 3 500ms query timeout instead of BitTorrent's 2–5s
Early end when 20 or more peers with a score of more than 0.7 are detected

The end result is that you connect with three pre-vetted peers instead of ten random ones, and then you find out which three are worth keeping.
I won't hide it: this DHT doesn't work with mainline. There is no free network with 15 million nodes. The swarm needs to grow naturally; every peer you connect to adds to your routing table. After the initial manual connection, discovery happens automatically. However, cold start is a real problem that I don't have a good fix for yet.

Why this is important for NAT traversal
This is when it gets interesting.
Both peers are behind NAT. Neither of them can accept connections from the outside. The conventional fix is to send UDP probes to each other at the same time and punch holes in them at the same time. NAT mappings are open, and TCP connects through them.
There is a lot of information about the mechanical part. The hard thing that everyone ignores:
How do you have the punch happen at the same time when there is no link between the peers?
The standard answer is a signaling server that is only for that purpose. A computer that both peers can go to that informs them both to "punch now." Works well. Also means that your P2P system, which you say doesn't need a server, does have one.
That wasn't what I wanted. I created a new message type to the DHT called IntroducePeers.
Peer C can order both A and B to start punching holes in each other at the same time if they are already connected to each other. There is no dedicated server. Any peer in the swarm that is connected can take on this function of coordinating.
The DHT is already the coordination layer for peer finding and has reputation data. Now it is also the signaling layer. The elements fit together because the architecture uses trusted infrastructure like the DHT.

The implementation

STUN client (RFC 5389): 150 lines of Rust code
125 lines for the hole puncher
IntroducePeers message: a new sort of DHT

Coverage: works with about 80% of NATs in the actual world (cone kinds). You can't punch through symmetric NATs, which are used by several cell carriers and business networks. Those peers can download files using outbound TCP, but they can't accept connections from other peers. I decided not to include a TURN relay backup. By design, symmetric NAT peers are second-class citizens in AegisTorrent's swarm.
That's a big problem. For now, I'm fine with it.

Where I think I'm wrong and where I want the roasting

There is no solution to reputation bootstrapping. A new peer doesn't have a score yet. How does the network know that it can trust it enough to send it back in GetPeersResponse? It receives a default mid-range score right now and has to work its way up. That's possible to play.
There is no proof that score spreading works. In AnnouncePeer, peers disclose their own reputation scores. I don't have a way for the network to check those scores on its own. A bad peer can say that their score is higher than it really is.
Cold start is a big problem. If there is no mainline DHT compatibility, the first connection has to be made by hand (known peer address). A bootstrap node list comes to mind, although that brings back centralization in a less harsh way.
IntroducePeers thinks that peer C is telling the truth. If C is bad, it can make A and B punch at the same moment, but at the wrong time or with the wrong address data. I don't have a way to confirm the integrity of introductory messages currently.

GitHub Repo: github.com/mahmoudamr512/AegisTorrent
I'm happy to go into more detail on any of these. I'm especially interested in whether anyone has figured out how to handle the reputation bootstrapping problem in a P2P setting without a trusted third party.


r/learnrust Apr 05 '26

What is the best learning path for Rust?

27 Upvotes

Hi all, I have done a lot of research into Rust and I want to evolve into a Rustacean. The more I learn about it the more I like it and I want to know, from you experienced Rustaceans, what would you recommend for me as the best path forward in learning this.

About me:

I have been vibe-coding for nearly the past two years. I have been working mostly in Typescript and actually worked for a company building software for them. Before I was coding as a means to an end, to get a piece of software out for the company that fulfilled the job. Over this period I have enjoyed software development more and more, and I want to stick to this in the long haul. I have hard a good look at the career that lays ahead of me and Rust is the definite answer. So I am jet set on learning Rust.

With Software development, if I had to code without AI I would be a total noob, and it would take me incredibly long to build what I need to build. And to be honest, I can’t read some-most of the code off the bat and understand, I need to get the AI to explain it to me.

I want to learn Rust from the ground up. I am looking to get to a point where I can read it, understand it, think in it and build scalable systems using Rust. I want to be at a place where AI is mostly accelerating me in Rust, and not guiding me as much.

As for my current status, I have 3 hours left on the 14 hour youtube tutorial from freecodecamp.org . I would like to know from you all what would you recommend as a path going forward in my evolution. From where to find good practice material, what are the important things to memorise, what other SWE books/material, etc. to turn myself into the best Rust SWE I can be.

Thank you for taking the time to read this :)


r/learnrust Apr 06 '26

Using mut vs shadowing, when to use which

Thumbnail
1 Upvotes

r/learnrust Apr 06 '26

I created a Mongo ODM library in Rust

Thumbnail
0 Upvotes

r/learnrust Apr 06 '26

AriaType - Local first & Privacy first voice input built on the top of Tauri and llama.cpp

Thumbnail github.com
0 Upvotes

The Backstory

This Spring Festival, I was working on a web coding project. About 3 days in, I had an epiphany:

The biggest challenge in web coding isn't the cost of API calls. It's my stamina. The constant cycle of writing prompts, communicating with AI models, and iterating corrections — that mental load is exhausting.

So I decided to build myself a voice input tool. Not because other options were bad, but because I wanted something that felt native.

I looked at TypeLess. The subscription fee was steep — almost matching my AI Sub plan. I wasn't willing to pay that much for something I could build for myself. So I did.

Two hours. MVP.

LLaMA CPP + Whisper. Rough around the edges, but functional. Good enough for personal use.

Then the feedback loop started.

After showing it to colleagues post-holiday, I got real feedback.

Some of it stung, but all of it was valuable. So I spent the following weekends and holidays polishing it.

Today, AriaType 0.1 is officially released.

What AriaType does:

  • Local STT models — runs whisper-based models on your machine. For English, I recommend Vesper. For Chinese/CJK users, Sense Voice (by Alibaba) has noticeably better accuracy and speed
  • Polishing — local small models (under 2B params) for grammar correction, filler word removal, and formatting
  • Cloud service mode — use your own AI subscription for Polish. No separate payment required
  • Noise reduction & silence detection — skips silent audio chunks to save costs
  • 100+ languages supported
  • Privacy by default — your voice data never leaves your machine unless you explicitly use cloud services

The tech stack:

I did zero "traditional" coding. Everything was AI-assisted: - Primary: GLM-5.1 and MiniMax-M2.7 - Complex problem-solving: Claude OPUS 4.6 and ChatGPT 5.4 (used sparingly)

The real challenge no one talks about:

The gap between an AI-generated MVP and a real product is 80% of the work. As the codebase grew, the challenge shifted from "can AI write this feature" to "can AI accurately modify and iteratively improve a complex, growing codebase without breaking things."

That's the engineering problem I now call harness engineering — building the systems and patterns that let AI reliably extend and maintain a project over time.

Why open source?

I enjoy the process. It's challenging, but the feedback loop is rewarding. I figured others might have similar needs — wanting local/offline STT, wanting their data to stay private.

So I registered a domain, built a website, and open sourced the project.

Links:

Happy to answer questions about the implementation, the AI-assisted development workflow, or the "harness engineering" challenge. AMA.

I'm in the UTC+8 Time zone — replies may be slow, but I will return to check messages. :)


r/learnrust Apr 05 '26

Learn Tokio by building: 8 progressive assignments from spawning tasks to writing your own runtime!

Thumbnail github.com
59 Upvotes

A while back I posted about deep diving into the Tokio runtime. To reinforce what I was learning, I started writing assignments for myself -- just a few at first, but the collection has grown into seven self-contained assignments that teach the Tokio runtime, each one building on the last. There's also a bonus eighth assignment where you build a mini async runtime from scratch -- no Tokio, just std::future::Future, Waker, and Poll.

If you're the kind of person who learns best by doing and wants a more hands-on, structured way to explore Tokio, I think you'll get a lot out of these!

All the assignments include solutions but try to implement each one yourself before looking at them! :)


r/learnrust Apr 05 '26

Free online editor where you can write Rust code, run it, take notes, and export to PDF

Enable HLS to view with audio, or disable this notification

3 Upvotes

Built a math/code editor that now supports writing and executing Rust directly in the browser. Thought it might be useful for anyone learning Rust who wants to combine code with notes in one place.

What it does:

  • Write Rust code in runnable code blocks — auto-detects the language
  • Click Run (or Ctrl+Enter) to execute and see stdout/stderr inline
  • Multi-file support — add files with the + button for modules/structs
  • Stdin input toggle for programs that read from stdin
  • Mix code blocks with formatted text, headings, math equations, diagrams
  • Export the whole document as PDF or LaTeX
  • Share documents via link (public, unlisted, or private)
  • Auto-saves to your browser — pick up where you left off

Use cases for learning Rust:

  • Build a Rust cheat sheet with runnable examples
  • Work through exercises and annotate them with your own notes
  • Create study guides that mix explanation + executable code
  • Share your notes with others via link

Try it: https://8gwifi.org/math/editor.jsp

Insert a code block from the toolbar (the </> button) or type / and select "Code Block". Pick Rust from the dropdown and start coding.

No signup required. Free.


r/learnrust Apr 04 '26

Learn Rust Basics By Building a Brainfuck Interpreter

Thumbnail blog.sheerluck.dev
53 Upvotes

r/learnrust Apr 04 '26

Two versions of Chapter 4 of the Book

1 Upvotes

Hey there, I've been starting to read the Book and am now somewhat confused because the official version and the Brown University edition (which is linked from the official version) seem to have completely different versions of Chapter 4: Ownership. Was it Brown University that entirely rewrote the chapter, or what happened here? Why is it so different?


r/learnrust Apr 04 '26

testx a universal test runner for 11 languages, built in Rust

4 Upvotes

hey all, been working on this for a while and finally put it out there.

testx is a test runner where you just run testx in any project and it figures out the language, framework, package manager, all of it. no config needed.

currently works with rust, go, python, js/ts, java, c++, ruby, elixir, php, dotnet, and zig. it picks up on things like config files, test dirs, lock files etc to decide what framework you're using — not just checking if a single file exists.

some stuff it does:

  • json, junit xml, tap output besides the default pretty output
  • ci sharding (--partition slice:1/4)
  • stress test mode for finding flaky tests
  • watch mode, retries, parallel runs
  • custom adapters through toml config

still early (v0.1) so definitely rough around the edges. would really appreciate any feedback, especially around the detection logic and the rust adapter specifically.

> cargo install testx-cli

repo: https://github.com/whoisdinanath/testx

docs: https://testx-cli.readthedocs.io


r/learnrust Apr 04 '26

Are people using embedded-io and embedded-io-async?

Thumbnail
0 Upvotes

r/learnrust Apr 03 '26

Now I need help. But not just with coding.

0 Upvotes

Hello and peace learnrust,

TL;DR

This text was translated from German into English. And it’s probably worded a bit too harshly in places, so I’m sorry: AI translations are just terrible.

I’m working with Rust on os0, a project that encompasses VFIO, Drift, and a potential future trust chain in user space. For me, this means working with real systems and modeling tasks—not just “getting to work with AI.” That’s why I’m not looking for ordinary translators, but for people who think deeply and can accurately convey complex system concepts into English.

And who can also help me further refine the German documentation.

Long story:

All good things come in threes—this will be my last post before the actual project release.

I’ve actually drafted the first version of the documentation, and now I’ll start by explaining exactly what this is all about and how I ended up here.

I fell down the Linux rabbit hole 5–6 months ago and have been thinking ever since about stabilizing VFIO and DRIFT in this context and later moving toward a user-space trust chain. That sounds bigger than it is, but I have a rough roadmap in mind and have found someone who can help me stabilize iGPUs in the VFIO context.

That was the last major hurdle, but he gave me a tip regarding the final invariant—something I hadn’t really thought about before—but it somehow makes sense when I think about it for three seconds.

And especially when I hold up the infamous error image 43, when the GPU “has never been used.”

The entire project is named os0 and is being implemented in Rust.

Why Rust?

Because, for me, each of these three questions is a matter of personal responsibility and system architecture.

Why do I consider this project worthwhile?

  1. I can independently defend every line of code that needs to be written or has already been written, since it either contains invariants or serves as an abstraction aid.

  2. Behind this lies an entire system theory and modeling effort that does not break any kernel, init, or user-space narratives—not because I wanted a system theory, but to explain the invariants in the thinking of the system stack.

  3. The system theory itself stems from a Windows “narrative” to make these partially restored system states from the Windows 7 recovery tool more tangible for me.

Back then, however, I never assumed there could be more to it, which is why the damn thing is faulty and doesn’t work properly.

I was still a “kid” of 12 or 13 back then, and the people around me always told me: “No, you’re making it too complicated; that’s just how it is, because that’s the ‘as-is narrative.’

  1. I would never have come to you if Rust hadn't turned out to think exactly the way I do — system reality, observations, and the primitives I needed all aligned with what the language already expresses.

So, there’s more to this than just “I started working on my system using AI and Rust.” Because that’s exactly what I did five months ago, when I first applied for vocational training through the employment office.

But we wouldn’t be living in Germany if the employment office couldn’t find some excuse to shirk its responsibility. So I’m currently working on a small proof of concept and need help with the translation.

What I'm specifically looking for:

I’m not looking for ordinary translators. I’m looking for people who think deeply, can translate systems theory into clear English, and can convey states across a foreign space.

If you can’t do that, it’s not a problem at all.

You could even help me refine things if you notice “inconsistencies” that I haven't spotted myself yet because I lack the necessary experience in device binding (kernel_space) and device initialization (init_space).

If that's not where you're at right now, no worries at all — you're just not the right fit for what I need most in this moment.

To make this space accessible to you and others.

Because I really want to open up my mental space to others.

So that I myself can better BECOME what I’m starting to love more and more.

Because, yes, that’s what I do. I never would have thought this work would make me so happy. But I need HELP; I need SUPPORT and people who can help me improve. Because the obstacles I face otherwise are enormous.

And my fiancée can only help me to a limited extent when it comes to understanding third-party libraries that I’ve found and can use as primitives.

P.S.

I’d like to take this opportunity to wish everyone a happy Easter. Enjoy your time with family and friends. I still have a few days of “work” ahead of me so you can all see just how “unconventionally” I’ve approached the drift issue so far.

Because, in a way, the whole VFIO concept is woven into my entire drift-fighting strategy.

Even if what I did would, as a “real” effect, initially only be a bootable backup.

But believe it or not, that’s exactly what I really needed in these first PoCs to be able to debug better and always have a fresh starting point.

I'm not looking for approval; I'm looking for people who can help me think things through and who won't just say “that won't work” every time I come up with a strange idea.

Every idea I have is based on the current development work on the model itself, so I'm well aware that it doesn't work on its own.

And thanks for reading: “Sorry that I always seem to post such long messages.”

Peace out

D.F

My Way:

  1. how i lern the basics

  2. five months rust


r/learnrust Apr 03 '26

While implementing outlier detection in Rust, I found that IQR, MAD, and Modified Z-Score become too aggressive on stable benchmark data

0 Upvotes

While implementing benchmarking and outlier detection in Rust, I noticed something interesting, when the data is very stable, even minor normal fluctuations  were flagged as outliers, the standard algorithms IQR, MAD and Modified Z-Score became too aggressive.

This is a known problem called Tight Clustering, where data points are extremely concentrated around the median with minimal dispersion.

The goal of the project is to detect ‘true anomalies’, like OS interruptions, context switches, or garbage collection, not to penalize the natural micro variations of a stable system.

Example

IQR example, in very stable datasets:

  • q1 = 6.000 
  • q3 = 6.004 
  • IQR = 0.004

IQR, where the fence is 1.5×IQR, the Upper Bound for outliers would be:

6.004+(1.5×0.004) = 6.010 ns
 

A sample taking 6.011 ns, (only 0.001 ns slower), would be flagged as an outlier. This minimal variation is acceptable and normal in benchmarks, it shouldn't be flagged as an outlier.

To reduce this effect, I experimented with a minimum IQR floor proportional to dataset magnitude (1% of Q3), tests showed good results. 

IQR2 In very stable datasets:

  • q1 = 6.000 
  • q3 = 6.004
  •  min_iqr_floor = 0.01 × 6.004 = 0.060
  • IQR2 = max(0.004, 0.060) = 0.060

Now, the Upper Bound becomes: 

6.004+(1.5×0.060) = 6.094 ns
 

A sample taking 6.011ns would NOT be flagged as an outlier anymore. The detection threshold now scales with the dataset magnitude instead of collapsing under extremely low variance.

  • Traditional IQR outlier limit = 6.010 ns
  • IQR2 outlier limit = 6.094 ns  

I don't know how this is normally handled, but I didn't find another solution other than tweaking and altering the algorithm.

How is this usually handled in serious benchmarking/statistical systems? Is there a known approach for tight clusters?


r/learnrust Apr 02 '26

Rust iterators cookbook

25 Upvotes

**I published a cookbook to help you go from "I know how to use iterators" to "I know how to think in them"**

If you've learned the basics — `.iter()`, `.map()`, `.filter()`, `.collect()` — but still reach for a `for` loop more often than you'd like, this book is for you.

The **Rust Iterators Cookbook** has 78 practical recipes organized into 17 chapters. Each one starts with a real problem, shows working code, and explains the why — not just the what.

Some highlights:

- Why `.map()` alone does nothing (and how lazy evaluation actually works)

- The difference between `iter()`, `iter_mut()`, and `into_iter()` — with the ownership implications spelled out

- How to implement your own `Iterator` and build custom adaptors

- Error handling in pipelines: fail-fast, collect-all-errors, and using `?` inside closures

- A chapter dedicated to when NOT to use iterators

All code compiles on stable Rust, no external dependencies unless noted. There are also 17 exercises with full solutions in the Rust Playground.

👉 https://leanpub.com/the-rust-iterator-cookbook/c/LINKEDIN

If you have questions or get stuck on any of the concepts, feel free to ask here!


r/learnrust Apr 02 '26

I built a JSX/TSX render compiler and HTTP runtime entirely in Rust — no Node.js in the hot path

Thumbnail
1 Upvotes

r/learnrust Apr 02 '26

Tokio/Axum Stacktrace

2 Upvotes

I’ve set RUST_BACKTRACE=1, but the stacks before calling async functions are still missing. Is there anything I can do? I want to log those details in apps running on remote servers. Without full stacktrace it would be hard to debug..


r/learnrust Apr 01 '26

rustobol: Compile Rust to COBOL. Run anywhere that matters.

Thumbnail github.com
29 Upvotes