r/learnrust

fs::read_dir can locate a file but fs::read_to_str can't open it

I have some code where I need to parse a file to generate a character tree. However, the main access point is supposed to be through the directory.

Essentially, when I perform a read_dir on the directory, the correct file is found. Then the path of this new file is passed into a different function, and the new function tries to perform a read_to_string of the path.

At this point, the code panics with the error message "No such OS or Directory found". I checked the source code for read_to_string, and it appears that it uses File::open()? under the hood. Any ideas why this may be failing? I'm running ubuntu on a WSL system, btw.

Edit: I forgot to say before that the file and directory both have read permission for all users

reddit.com
u/Scary_Competition_11 — 12 hours ago

Oh my... learning about Smart Pointers

I just worked my way through the smart pointer chapter of the rust book. Oh my...
Everything makes total sense, it is not unclear and everything goes well into how working thus far with rust feels.
But it feels like when writing software you can very quickly shoot yourself in the foot with assigning strong and weak ownership to the wrong variables.

Do you really need to break your head around how to structure everything regarding ownership with weak and strong references, or will it come somewhat naturally?

reddit.com
u/icecream24 — 18 hours ago

Embedded Rust Software development environment setup

To help people to get the best out of the code examples in my book (Manning), I have just written a summary of all of the various tools and configuration steps needed to do some embedded Rust development.

This include setting up cross-compiling targets, Arm embedded tool-chain, QEMU, gdb-multiarch, OpenOCD, probe-rs, st-link tools, serial communication tools, PICSimLab, and all that jazz. This setup can be use as a base for any embedded Rust development although currently its assuming that you are using a Cortex-M based MCU and Ubuntu as an OS. I hope this might help some of you getting started.

https://github.com/dcabanis/Embedded-Software-With-Rust-Book/blob/main/embedded-rust-ubuntu-setup.md

u/Independent_Egg_630 — 2 days ago

What one skill, if developed excellently, would have the greatest positive impact on my career?

I was just reading this book and I came across this question. It really made me think. So I started asking around to my friends, seniors, professors etc to get their insights.

One answer that I got from my professor really worried me. He said that only those who know about "agentic AI" ( AI which does heavy duty stuff on its own) will get anywhere in the current market. He feels that Software engineering will die out within 5 years and only machine learning would have job security.

I have been learning Rust for the last 1 year. I will not lie the consistency of my learning at first was bad and was not really putting in 8 hrs a day but now I am slowly changing it. I took up Rust though it had a high learning curve because I see the growing job opportunities for Engineers who are trying to migrate their existing C++ or Go systems to Rust for better performance. My ultimate goal would be to take up senior migration roles which generally require 3-5 years of experience. But currently I want to build backends and want to get a job as a fresher in Rust to gain experience and put a foot in the door.

>But this was the challenge thrown to me by my professor. He asked "So you will become a good Rust developer and you migrate a repository. What do you do after that".

I was quiet then. I knew that my professor was correct. In established companies, they would just have to migrate the code once. So essentially my job would be done at that time. My professor then mentioned that in a few years the AI would have the capability to monitor the system find the bugs and even fix it on its own and at that time I had absolutely no answer.

After thinking a lot about the conversation two things struck me:

  1. I heard that developers are rewriting the Machine learning libraries into Rust to get a great performance boost.
  2. With CUDA support for Rust available I can work on creating libraries for highly computationally intensive workloads on a GPU.

I took these points to my professor and since my degree is in AI/ML he was convinced that it is a great plan. He said that if I continue building ML libraries in Rust and utilizing the GPU to maximize performance, I will have a great future. He said that today the industry is turning towards Senior developers acting as Architects who will then use the AI to write actual code and all the developers will have to do is test the code.

So I think this is what my future looks like now. The market is indeed turning drastically and we are seeing lots of layoffs due to AI. However I feel that by building models and converting those models into libraries I might be safe for the future.

What do you all think? What is that ONE skill which will have the most positive impact on my career in the near future? I am a bit confused and need guidance.

reddit.com
u/kazuto-09 — 3 days ago
▲ 90 r/learnrust+2 crossposts

Engineer Answers Rust Questions | "Compile Time"?

Mostly for fun but might be useful for someone coming from Javascript, Python etc.

youtube.com
u/rustcurious — 3 days ago
▲ 12 r/learnrust+1 crossposts

Rust linter for method ordering (looking for feedback)

Hi,

I'm learning Rust (I have experience with Java and Go) and built a small linter funcorder-rs.
It checks that inside impl blocks, methods are ordered as:

  1. Constructors (pub fn new() -> Self etc.).
  2. Public methods.
  3. Private methods

More than looking if you guys find it useful (which it's also nice) I am wondering if I am using idiomatic Rust, best practices, etc.

This is the link: https://github.com/manuelarte/funcorder-rs

Cheers!

reddit.com
u/manuelarte — 3 days ago
▲ 2 r/learnrust+1 crossposts

Rust

I have like 130 hours, and I am enjoying the game. Ik a lot of the mechanics off of watching dozens of hours of different youtubers before playing rust but I am not good at pvp-ing (though i enjoy it) and I don't get monument puzzles at all. I've been trying to find teammates to play with but the ppl on discord servers either don't wanna play with sb new or are annoying af. How do I find fun ppl to duo, trio, quad, or whatever. I'd really love to get into Rust properly but it's tough.

reddit.com
u/Puzzleheaded-Act2414 — 3 days ago

Interator Initialisation Question

So, the idea behind Iterators is that they are Lazy and don't do any work until called. But at the same time Rust likes to have fully initialised objects.

So, if my initialisation takes considerable time (think opening a file, connecting to a network, etc) should I do that in the constructor of the iterator so that it is fully initialised, or at the first step in the iteration so that the Iterator is lazy?

I waffle backwards and forwards on this myself and would love to know what the consensus is.

e.g. Something like

struct MyIterable {
    network:OpenSocket,
}
impl MyIterable {
    fn new(args:Args) -> Self {
        // might take a long time
        Self { network: open_network(args) }
    }
}
impl Iterator for MyIterable {
    type Item = String;
    fn next(&mut self) -> Option<Self::Item> {
        network.get_next()
    }
}

vs something like

struct MyLazyIterable {
    args:Args,
    network:Option<OpenSocket>,
}
impl MyLazyIterable {
    fn new(args:Args) -> Self {
        Self { args, network:None }
    }
}
impl Iterator for MyLazyIterable {
    type Item = String;
    fn next(&mut self) -> Option<Self::Item> {
        if let Some(network) = self.network.as_mut() {
            network.network.get_next()
        } else {
            // might take a long time
            let network = open_network(self.args);
            let item = network.get_next();
            self.network = Some(network);
            item
        }        
    }
}
reddit.com
u/dgkimpton — 4 days ago
▲ 23 r/learnrust+2 crossposts

Finding a Rust backend job with 1.5 years of production experience?

Hey everyone,

I’ve been a backend/systems dev for about 3+ years now. My background is mostly heavy infrastructure stuff—Kafka, NATS, ScyllaDB, MySQL, and Postgres. Currently, I’m actually knee-deep in a migration of 1,000+ tables from CockroachDB to Postgres using Kafka CDC, so I’m used to high-scale, "messy" production environments.
For the last 1.5 years, I’ve been using Rust professionally at my current company. I’ve completely fallen for the language and the ecosystem—I even spend my free time building Rust tools, like an open-source html to typst parser I recently published.

The problem is, I’m trying to move into a 100% Rust role, and I’m hitting a massive wall.

It feels like every posting I find is either:

  1. The "5+ years of Rust" unicorn: Which feels like a huge ask for a language that only recently went mainstream in the enterprise.

  2. Web3/Crypto: I have zero interest in this space. I want to build distributed systems, CLI tools, or infra.

I’m starting to get ghosted or rejected because I don’t have that "5 years" mark, even though I have solid systems experience and 1.5 years of actual production Rust.

I’m curious:

• For those of you who hire for Rust teams: Does 1.5 years of professional Rust plus a strong systems background (Kafka/Scylla/K8s) actually get me a look? Or is the 5-year filter usually a hard "no"?

• How do you guys find the "normal" backend roles that aren't crypto? Are there specific job boards or Discord servers that are better than the LinkedIn noise?

• Should I be focusing more on my open-source stuff to "prove" I know the language, or does the professional experience carry more weight?

Would love a reality check or any advice from people who’ve made the jump recently. Thanks!

reddit.com
u/Away-Resolve787 — 5 days ago
▲ 68 r/learnrust+1 crossposts

Free demo live! I built a stable solar system generator & space colony sim from scratch in Rust with wgpu, N-body gravity, thousands of objects. I wanted to learn rust, and this was my method.

I'm Dave :) I've been here a couple times before, showcasing my passion project Stella Nova, built in pure Rust using wgpu for rendering. It's a colony management simulator set in a procedurally generated solar system where every object follows real N-body gravitational physics. The custom engine (WarpCore) handles thousands of entities stably at once and ships under 500MB on disk!

Current functional demo systems:

Real Hohmann transfer planning for interplanetary travel
Modular station construction
Citizen AI with state machine behavior (think RimWorld, Dwarf Fortress)
Time dilation control, play with the laws of relativity
Secret programming menu (please ask)

The playable demo just went live on Steam: https://store.steampowered.com/app/4703440/Stella_Nova_Demo/

Happy to answer any architecture or other questions about the project!!

u/DavesGames123 — 5 days ago
▲ 52 r/learnrust+1 crossposts

Wrote a book on embedded Rust based on years of teaching the language, looking for learner feedback on the early chapters.

I teach Rust at a training company called Doulos. Two courses, one on the fundamentals and one on embedded systems, both running for about six years now. After enough engineers come through those classes you start to notice the same problems coming up, often not the things the books and tutorials spend most of their time on. That eventually became a book, and Manning have just put the first four chapters on early access.

It's called Embedded Software with Rust. Now, embedded is a fairly niche thing in this sub, so I should be honest about who this is for: the book assumes you already know some embedded C or C++. If Rust is your first systems language and microcontrollers aren't on your radar, this isn't the book for you, and I'd rather say so than have anyone spend money on something that doesn't fit.

The reason I'm posting here anyway is that some of what the early chapters cover comes up for any Rust learner eventually. What no_std actually means. Why the toolchain looks the way it does. How a Rust program starts up before main() runs at all. Several students over the years have told me that working through embedded examples is what finally made Rust's design decisions make sense to them.

What I'd find useful from this sub: if you've tried embedded Rust and bounced off it, or wanted to try and didn't know where to start, tell me what would have helped. The unwritten chapters are easier to reshape than the ones already through editing, and that's the entire reason MEAP exists.

reddit.com
u/Independent_Egg_630 — 6 days ago
▲ 1 r/learnrust+1 crossposts

rust embedded bus lockup? ( i think need some insight)

context: i have a bmp390 and mpu-6050 running on the same shared I2c bus using the rust embassy framework to essentially use a criticalRawMutex to share the bus, and a lis3mdl on the SPI they were working perfectly fine had them run for 2-hours ish for some graphs and data but then i added my KF (kalman filter) implementation and boom the sensor fusion to it first after about 10-15 seconds stop sending I2C readings? cause the kalman filter starts running on predict only essentially (readings change like 0.001 each dt, then the KF itself runs till about 38-39 seconds, then also boom, no hard panic or fault or anything like that just silence from demft,
can anyone provide some insight???
also i can post defmt logs if that would

reddit.com
u/awh-emb — 5 days ago
▲ 39 r/learnrust+1 crossposts

Built a zero-copy CSV scanner in Rust from scratch — no csv crate, no AI writing the code.

This started as a learning project . While building it I accidentally learned byte-level char comparison and realized I could push it further.

Results on 2M rows (224MB):

- 287 MB/s throughput

- 779ms total

- Faster than the csv crate on my machine

How it works: instead of allocating strings per field, it stores byte offsets (start, end) into the raw buffer. Zero heap allocation per field. The bottleneck is now disk I/O, not the parser.

Still early — no iterator API yet, delimiter is hardcoded to comma, exact match search only. But it works correctly including buffer boundary handling.

GitHub: https://github.com/ahmadzafarcs/zirc

Looking for honest feedback — especially on the buffer boundary handling and anything I'm doing wrong that I can't see yet.

u/Easy_Pin_9346 — 8 days ago

How do you secure the supply chain and keep control of dependencies in your projects?

The recent TanStack vulnerability over on NPM has me wondering, how do you secure your crates supply chain? I'm still VERY new to rust, but when I compile a rust project, I notice that it compiles a bunch of other crates before it compiles the target.

When you pull a crate as a dependency in Cargo.toml, I'd assume that crate would pull in it's own set of dependencies. How would you go about vetting and making sure that the crates being pulled in are safe? Would it be better to reduce your set of dependencies to avoid these potential attacks?

Sorry for the really dumb question, but I'm curious as to how we can defend against this in our projects especially after seeing whats going on over at NPM.

reddit.com
u/cometomypartyyy — 8 days ago