r_rust🦀 – Telegram
r_rust🦀
62 subscribers
565 photos
65 videos
36.1K links
Posts top submissions from the rust subreddit every hour.

Powered by: @reddit2telegram
Chat: @r_channels
Download Telegram
Beginner Vscode extension with a rust backend

Hey guys, this is my first post in this subreddit. I started learning rust a couple of months ago and I think it's time for my first big project. I'm thinking of building a vscode extension that parses large log files using a rust backend, I'm aware of existing tools like klogg but those are seperate apps, it would be interesting to have vscode do that don't you think ? Anyways the biggest hurdle i have is of course memory handling: dumping the entire thing in memory is just not feasible, at first i thought of using memmap2 crate but after a bit of research i noticed that accessing data that was truncated will lead to panics and accessing lines that were added to the log file after initial mapping will simply not show up and I'll be forced to remap it again and as you know, log files keep rotating and new logs are constantly being added to them. What do you think i should do ? Should i just stick with std::fs::File with Seek ? I need something that allows me to access a specific byte offset in O(1) in both time and space complexities. And by the way, would you use such a tool ?
Rust has been quite the adventure for me and I'm enjoying it so far (although it took me half a day to implement a linked list lol)
Thank you guys for your input and have a good time with your families.

https://redd.it/1pvaoyp
@r_rust
Changed my rust interview prep after bombing a lifetimes question

Had a Rust-heavy backend screen recently where I completely fumbled a pretty basic lifetimes question. The task itself was simple, the painful part was trying to explain why the code compiled while my brain was still stuck in Python and LC habits. I left the call realising most of my prep had almost nothing to do with how I actually write Rust.

Since then I have been changing the routine. I still warm up with a few LC-style problems, but I rewrite the interesting ones in Rust, run them in the playground and let rust-analyzer and clippy complain until the ownership story feels clean. I keep a small note file with “before / after” snippets for lifetimes that confused me so I can revisit them later instead of relearning the same thing from scratch.

For the “talk through your solution” part I rotate between a Discord study buddy, quick whiteboard sketches in Excalidraw and short mock rounds in a couple of interview tools like Pramp, interview solver and Beyz coding assistant to practise saying the ownership and lifetime reasoning out loud under a timer.

If you have been through Rust-heavy interviews, did you get more out of extra LC-style drills or from this kind of Rust-specific explanation practice?

https://redd.it/1pvdeis
@r_rust
I built a tiny 2-qubit quantum simulator in Rust to learn the math

Hey everyone,

I’ve been diving into quantum computing lately and decided to build a lightweight simulator called QNano to help me wrap my head around what’s actually happening under the hood.

It’s limited to 2 qubits for now, but it’s been a great exercise in mapping the quantum gates into code.

https://preview.redd.it/wmwx28gjnd9g1.png?width=1200&format=png&auto=webp&s=58a996bdca99a1bccf738aab8771253e41edc0d8

(https://preview.redd.it/i-built-a-tiny-2-qubit-quantum-simulator-in-rust-to-learn-v0-7znchopend9g1.png?width=1200&format=png&auto=webp&s=933ed8271885bd927b89f748079f7073d4bbbf94)

What it does currently:

Uses a custom `.qnano` assembly-style syntax to write circuits.
Handles complex probability amplitudes (so it tracks phase, not just basic probability).
Supports 7 gates: H, X, Z, S, T, CX, and CZ.
Correctly simulates entanglement (Bell States) and interference.

What’s next: I’m working on a CLI visualizer using Ratatui so I can see the "wires" in the terminal, and I still need to implement a proper measure function.

If you're interested in the math or want to see how to handle complex state vectors in Rust, the code is up on GitHub.

https://github.com/Cqsi/qnano

https://redd.it/1pvgyq4
@r_rust
LeSynth – Fourier 1.2.0 is out.

🎁 Consider this a small Christmas gift update

https://github.com/hlavnjak/lesynth-fourier
https://www.kvraudio.com/product/lesynth---fourier-by-jakub-hlavnicka

https://preview.redd.it/o4yd60fgld9g1.png?width=1713&format=png&auto=webp&s=13197b65fefa8b5a65e97dbf86540867013c3c80

What’s new:
• Windows VST scanning fixed
Resolved an issue where the plugin wasn’t detected by most Windows DAWs due to an unusual plugin file extension. The plugin now scans and loads correctly.
• Resizable GUI fixed
Proper dynamic resizing is now fully supported. Previously, proportional resizing didn’t work correctly for all components and the plugin incorrectly reported resizing as unsupported, so most DAWs disabled it. This is now fixed and reliable.
• Wobble modulation
Added an optional Wobble component for richer, more complex sounds.
Amplitude/time and phase/time curves for each harmonic can now be modulated across buckets/periods using constant and sine curve types, enhanced with additional sine-based Wobble modulation.
• Improved GUI
Cleaner, more refined user interface.
• Extended parameter range
New maximum values (0.025 and 0.05) for finer control and better parameter granularity.
• CLAP support
Added support for the CLAP plugin format.

https://redd.it/1pvgq2j
@r_rust
Vectarine: A game engine for ultra fast prototyping

I think that Rust is a great language for Game Dev (compared to C++) because of the performance benefits and the large ecosystem.

However, one drawback I've seen is that compilation time and working around the borrow checker can slow you down a lot when you are prototyping or just trying out random gameplay ideas. I feel like this is the case for Bevy (at least, when I tried using it).

I've built this game engine called vectarine to work around these issues by allowing lua noscripting (using the awesome mlua crate).

Link to the repo: https://github.com/vanyle/vectarine/

The interface looks like this (I'm using egui):

https://preview.redd.it/ru8yv7mk1e9g1.png?width=1824&format=png&auto=webp&s=217b9e69bf184decee953aad2e3f35b606ade4cd

I'm open to feedback. I'm planning to integrate 3d as the next step.

https://redd.it/1pvionw
@r_rust
low latency, zero copy networking pipeline in rust for multi producer single consumer like workloads

I have a long running program that ingests a lot of udp packet and then pushes them to listeners, latency is very crucial in here, currently i have an xdp program which filters the relevant packets and have n threads busy polling to rx queues of the nic, after getting the packet i am sending it to another thread which does some processing, dedup and fanout again using xdp. so its like a multiproducer - single consumer pattern.
here while sending the frame to the processing thread i am having to use copy from slice, then freeing the umem memory, in the recv thread loop.
is there any other way i can send to the processing thread and reduce this copy to only when absolutely required, mostly only after the dedup is done, so i dont have to call copy everytime which is expesive?
i was thinking of passing like the umem base ptr, index of releavent packet memory to the consumer thread and the giving it back to the recv thread again once its done processing.. but still it would block on on the recver thread waiting on for these freed packets to come in the channel. so kinda stumped here




https://redd.it/1pvhrvo
@r_rust
How do you handle std/nostd in Cargo workspaces?

I am working on a dual-platform library (Tokio + Embassy). Feature unification kills me - when my std adapter enables `std` on the core crate, it leaks into my no
std Embassy builds even with default-features = false.

My fix: Makefile that builds each crate individually with explicit --package and --no-default-features. Also build.rs noscripts that panic on invalid feature combos.

Is everyone doing this? Are there any better patterns?

https://redd.it/1pvlqic
@r_rust
I got tired of writing bad code repeatedly, so I learned Rust to do it only once and made a concurrent processing library - sandl

I'm a game designer and programmer - Sometimes (i.e., every time) I need to do some Monte Carlo simulations for esoteric dice/card systems. Of course, I could copy and paste from older files, but that's an annoying workflow to change up when I come up with new random number generators. To solve this and other problems, I made this:

Repo, Crate. It's called sandl and it's pronounced just like you think it is. The name stands for "Slices and Layers", the key abstraction of the program.

Per the docs, it's a library for building parallel execution engines with dependency management, type-safe method dispatch, and event observation. Layers define behavior via methods, Slices provides args for each method they want to call.

This way, I can configure several thousand RNG workflows, simulate them all concurrently and collect the results neatly and fast-ly.

I'm also currently using it to make a TypeScript code generator so I don't have to write bog-standard CRUDslop routes and DTOs ever again. I also used it to solve the One Billion Rows Challenge a couple of months late.

It's my first real Rust code base and it has some real stinky hacks in it, but I'm overall happy with the result - Being able to make something actually useful (for myself) with a new language has been a nice surprise. I published it because, maybe, it's useful to you, too.

https://redd.it/1pvt6ax
@r_rust
Idiomatic Iterators and their performance

So, I've been going through rustlings and once I've reached the iterators section, the questions came in.

I have C and Go background, I also like digging into "how many instructions does this operation takes? is it optimal?", and I would like to clarify a couple of things related to Rust's iterators.

Here's the first question: what exactly output I will get compared to the for loop in this case? Will this iterate over a map again on each method call, or iterators are pretty smart to wrap into a single loop when compiled?

fn countcollectioniterator(collection: &HashMap<String, Progress>, value: Progress) -> usize {
    // collection is a slice of hash maps.
    // collection = { "variables1": Complete, "from_str": None, … },
    //               { "variables2": Complete, … }, …
    // ---
    // let mut result = 0;
    // collection
    //     .iter()
    //     .foreach(|m| result += m.values().filter(|&&v| v == value).count());
    // result
    // ---
    //
    // or
    //
    // ---
    collection
        .iter()
        .flat
map(|m| m.values().filter(|&&v| v == value))
        .count()
}

What about "Idiomatic Iterators" in the noscript of this post: how would you write these two pieces of code (one above and the one that is below)? Which variant would be more idiomatic in Rust, or all of them are being respected the same way?

fn main() {
let word = "hello";

let mut chars = word.chars();
let result = match chars.next() {
None => "None".toowned(),
Some(first) => {
let mut s = first.to
uppercase().collect::<String>();

s.pushstr(chars.asstr());

s
}
};
println!("{result}");

// or

let mut chars = word.chars();
let result = match chars.next() {
None => "None".toowned(),
Some(first) => {
first
.to
uppercase()
.chain(chars)
.collect::<String>()
}
};
println!("{result}");
}

And the last question: which variant of ones provided above is optimised the best under the hood? Does a call to `chain()` method requires some additional allocations that are less performant than a simple vector of characters? (I think this way because I deem Iterators are more complicated data structure than Vectors.)

Thanks y'all in advance!

https://redd.it/1pvzmsa
@r_rust
4 months later: update on my journey toward the Rust compiler team

Hi everyone,

some of you might remember my post from a few months ago where I wrote about contributing full-time to the Rust compiler, being close to team membership, but struggling to make it financially sustainable while living in Russia

A lot has happened since then, so here is a short update and a link to a longer blog post with details, numbers and answers to common questions

TLDR

I kept contributing consistently (171 contributions so far)
I could not relocate or take full-time offers
I officially became a member of the Rust compiler team
I returned to my previous job teaching IT to kids - it gives me enough financial stability and time to keep working on the compiler

Full blog post: https://kivooeo.github.io/blog/first/

If you are interested, feel free to ask questions in the comments

I want to collect questions that come up here and add them to the blog over time (feel free to ask in DM as well), especially if they might help others who want to contribute to the open source or find themselves in similar life situations

Thanks again to everyone who supported me back then. Your comments helped more than you probably imagine

Happy holidays and happy New Year to all of you! <3

https://redd.it/1pw5i9y
@r_rust
Looking for feedback - TUI text editor toy project

I wrote a TUI text editor with regex-based syntax highlighting, basic theming, and some Vim motions. It is very incomplete and not intended to be actually used; it was more a learning experience for getting to know Ratatui and a more OOP approach with mutable state.

I'd like to know what was done right and what is absolutely unidiomatic in the code.

https://github.com/AfkaraLP/sexditor

https://redd.it/1pwbep2
@r_rust
I built an immutable, content-addressed Python environment manager in Rust

px (Python eXact) is an experimental CLI for managing Python dependencies using immutable, content-addressed environment profiles (no venv).

👉 https://github.com/ck-zhang/px

It is now in alpha, feedback is welcome :)



https://redd.it/1pwawtm
@r_rust
I built a simple terminal Snake game in Rust

https://i.redd.it/v6f63de4ll9g1.gif

I wanted to build a simple project while reading the book, so i decided to go for the classic choice
Link to the github repo

https://redd.it/1pwccjc
@r_rust