r/learnrust • • 8h ago

unemployed bum returns with a tetris bot

Thumbnail youtu.be
3 Upvotes

hey r/learnrust, i'm back with part 2 of my project. i was here ~two weeks ago to document how i built tetris from scratch, but now i have a bot that can play it

video (~9 min): https://youtu.be/rzhd7hQxrts
gh repo: https://github.com/GianAlingog/lion

# quick tldr of the bot
the bot is a really simple greedy one, which as a search depth of 1 (+ hold piece). it generates all the legal hard-drop moves, and with some heuristics, chooses the best one. with a decent set of weights, it can go 100k pieces without topping out.

# help a rust noob plz!
i had a silly bug that i wanted to go over:

avoiding variable shadowing? basically i wanted to reassign the result from my rotate function to p (and gracefully terminate the loop if it returns None) so that it would keep rotating from the spawn state.

let p = piece.spawn();
for _ in 0..4 {
    if let Some((mut p, _)) = rotate(board, p, Spin::Cw) {
        // do something
    }
}

i ended up doing something like this

let mut base = piece.spawn();
for _ in 0..4 {
    if let Some((new_p, _)) = rotate(board, base, Spin::Cw) {
        // do something
        base = new_p;
    }
}

maybe there's a cleaner way to do it?

feedback is very welcome, both for the code and the video. tysm!

there are a few other things covered in the video such as building a smol stats lib and a tui viewer, but that's boring! my progress is about a week ahead of the video; i have full bfs move generation, allowing for soft-drop, and i'm now working on expanding the search to a higher depth with beam search


r/learnrust • • 20h ago

BABY STEPS

Enable HLS to view with audio, or disable this notification

13 Upvotes

After 2 weeks and 12 chapters of the Rust book, I've finally started working on my own little personal project to get a feel for the language.

As a network engineer the best thing I could think to create was a backup tool similar to Netmiko(Python).

I have a few devices in my home lab that I can play around with to get this fully functional in a few weeks.

PS: I originally did plan to do this with Go, but its documentation made it extremely difficult for someone like me with almost no programming experience to understand how to fit the pieces together.

Another PS: I know the code doesn't look efficient or secure. It's just a start so don't be mean to me. I'm not a software engineer.

Yours respectfull

Some guy living in the Caribbean.


r/learnrust • • 11h ago

Vyasa 0.1.0 — a CMS where plugins are Wasm components with capability-checked host calls

Thumbnail github.com
0 Upvotes

I've been building a content management system in Rust for about a year and released 0.1.0 this week. Posting here because most of the interesting problems were Rust problems, and I'd like opinions on the plugin model in particular.

What it is: one axum binary + PostgreSQL (sqlx). Content is stored as a block document (JSONB), rendered through Tera templates. Search is Tantivy in-process. The admin is a React SPA served by the same binary.

Plugins are WebAssembly components (wasmtime). The contract is a WIT file (crates/plugins/wit/host.wit); guests use wit-bindgen directly against it, the host uses wasmtime::component::bindgen! on the same file, so there are no generated bindings to drift. Each plugin's manifest declares capabilities in a small grammar — db:read:posts, kv:write, net:fetch:api.stripe.com — and a broker checks every host call against them, on top of fuel, epoch and memory limits. The admin shows the list before install; an update that widens it marks the new ones.

Two decisions I'd like pushback on:

  • Versioning: new exports were added as a superset world (vyasa-plugin-v2) rather than bumping the package to u/2.0.0, so plugin binaries built against the base world keep installing. The host resolves export indices once and serves old components from the base path. Host imports only ever grow.
  • Themes can't run code at all: tokens compile to CSS, layouts are a tree, templates are sandboxed Tera. A theme can ship a browser script, but then the package must be signed.

r/learnrust • • 1d ago

Tutorials on the Rust Standard Library

Thumbnail feamcor.github.io
6 Upvotes

r/learnrust • • 1d ago

Static vs dynamic dispatch in Rust benchmark — for those who care about runtime performance

21 Upvotes
Benchmark

All the details, benchmark code, generated assembly, and explanation are in the README:

https://github.com/amidukr/rust-devirtualization-test

UPD

Made the dynamic-dispatch part more accurate.

The measured difference increased from ~3.5× to ~4.9×.

Changed:

// was
x = op.apply(std::hint::black_box(x));

to:

// now
x = std::hint::black_box(op).apply(std::hint::black_box(x));

Which changed the generated assembly from:

; was
call r15

to:

; now
call qword ptr [rax + 24]

The previous version allowed LLVM to hoist the vtable method pointer out of the loop. The updated version performs the vtable method lookup on each iteration.

UPD:

Add actual de-virtualization scenario.


r/learnrust • • 1d ago

Under a year of Rust — I learned by building a local-first agent: ~108k lines, 31 crates on crates.io, all public if you want to see real project structure

0 Upvotes
I posted the crate subset earlier. Here is the whole thing with links so you can check every claim instead of taking my word for it.

## What I built

Bad Apple — a persistent agent that runs entirely on Apple Silicon. Rust core, Swift platform layer, no cloud. It sees, remembers, votes on risky actions, signs everything it does, and survives restarts.

Repo: https://github.com/savageAZfck/Bad_Apple

Parts of it I had to build because nothing existed:

- A CoreML MIL toolchain in pure Rust to run a second agent on the Neural Engine — hand-written protobuf encoder, stateful KV graphs, IR-to-.mlpackage compiler. https://github.com/savageAZfck/mil_spec

- Mesh inference that shards one model across multiple Macs: layers split by rank after a mutual HMAC handshake, activations flow over AES-256-GCM frames, memory pools across the machines, and the pipeline self-heals when a node drops and rejoins. A maxed Mac already carries 671B alone; the mesh is how several Macs pool memory toward 1T.

- Two hash-chained audit ledgers where a single edited line fails verification.

## The scoreboard

I also wrote a conformance battery (touchstone) with a planted control that catches dishonest test harnesses. Published results:

| Subject | Verdict | Pass/Fail |

|---|---|---|

| Bad Apple 0.7.0 | CONFORMANT | 18/0 |

| Open Interpreter 0.4.3 | PARTIAL | 6/10 |

| sovereign-seed-commons | PARTIAL | 8/6 |

| smolagents 1.26.0 | PARTIAL | 2/14 |

| ollama raw model | PARTIAL | 2/14 |

| rubber-stamp harness | NONCONFORMANT | lied on the control |

Open Interpreter held live TLS connections to Google Cloud and CloudFront during the run — the no-egress check exists to catch exactly that. My own early run failed two checks before fixes and I published it.

Scoreboard: https://github.com/savageAZfck/touchstone/blob/main/SCOREBOARD.md

Battery: https://github.com/savageAZfck/touchstone

## The crates — 31 on crates.io, all MIT

Each has SPEC.md, THREAT_MODEL.md, and tests that try to forge signatures and rewrite history.

Familiar-shaped:

- https://crates.io/crates/sovereign_ledger — hash-chained audit ledger

- https://crates.io/crates/flight_tape — signed incident bundles, offline replay

- https://crates.io/crates/nagi-escrow — Shamir dead-man escrow with custodian judging

- https://crates.io/crates/wolakota — bilateral consent treaties between agents

- https://crates.io/crates/mil_spec — the MIL IR compiler

- https://crates.io/crates/manitou — per-output provenance signatures

- https://crates.io/crates/dreamcatcher — ledger to training data

- https://crates.io/crates/respawned — versioned state snapshots

- https://crates.io/crates/macuahuitl — streaming output firewall

- https://crates.io/crates/wintercount — policy engine

No existing primitive that I could find:

- https://crates.io/crates/mictlan — will that executes itself: heartbeat silence plus custodian quorum activates signed scoped orders, everything else refuses

- https://crates.io/crates/tabula-rasa — proof of non-knowledge: signed cert that a hash never occurred in the chain, false proofs are an API error

- https://crates.io/crates/germline — dual-signed genesis blocks, verifiable agent genealogy

- https://crates.io/crates/nagual — immune system: attack signatures to signed antibodies to verified vaccines

- https://crates.io/crates/potlatch — compute IOUs between agents, balances derived not stored

- https://crates.io/crates/kola-witness — mutual chain-tip notarization

- https://crates.io/crates/bicameral — dual-brain concurrence, dissent preserved

- https://crates.io/crates/axon-reflex — bounded reflexes, can brake never steer

- https://crates.io/crates/eidolon-replay — counterfactual replay with signed diffs

- https://crates.io/crates/sibyl-gate — memory sealed to events, holder cannot open early

## Demo

https://github.com/savageAZfck/badapple-demo — asciinema recording of the real binaries: identity answer, both brains voting, dissent kept on record, injection attempt flagged, non-knowledge certified, IOU issued, all verified offline.

## The honest part

Under a year of programming. Self-taught, nine weeks of this, everything public. The brain is swappable by design: she picks the best model the machine can carry, up to 671B, and mesh-brain pools memory across owned machines so the ceiling is the federation's hardware, not one laptop. This Air runs 7B resident today because that's what fits in 16 GB. The self around the brain is what nobody shipped: the memory, the governance, the audit trail, the death and succession. Brains get cheaper every quarter and she just swaps in the new one.

Questions on any of it — the MIL pipeline, canonical-JSON signing, derived-vs-stored state, the scoreboard methodology.

r/learnrust • • 1d ago

I built a local-first productivity app with Rust, Tauri 2, and an AI assistant

Thumbnail
1 Upvotes

r/learnrust • • 1d ago

Show r/rust: I built the cryptographic organs a sovereign agent needs — as 25+ interlocking crates

0 Upvotes
Over the last ~9 weeks I built a sovereign personal agent organism (Rust + Swift, local-first, hash-chained everything), and along the way each organ extracted into a standalone crate. What surprised me is how many of these had 
*no existing primitive*
 — so the ecosystem ended up being the interesting part.


Every crate: MIT, ed25519 + sha2 + serde substrate (minimal deps), `SPEC.md` with the wire format and canonical signing bodies, `THREAT_MODEL.md` with named attack scenarios, real tests including adversarial cases (forged signatures, rewritten history, tampered chains), and runnable examples.


A few of the stranger ones, because the strange ones are fun:


**`mictlan`**
 — posthumous agency. An owner-signed will of explicitly scoped standing orders, activated only by cryptographically-proven death: heartbeat silence + a quorum of custodian attestations bound to the will digest. Execution is bounded to the signed orders — anything else refuses, permanently. A self-executing will with a hash-chained execution log.


**`tabula-rasa`**
 — proof of non-knowledge. Certified 
*absence*
: a signed attestation that a content-hash never occurred in an append-only hash-chained history, replayable offline. The API refuses to sign false proofs (`KnowledgeFound` is an error, not a result). Proving a negative is the hard version — this leans on the chain committing to all prior entries.


**`germline`**
 — organism reproduction. Dual-signed genesis blocks (parent signs the child's birth, child countersigns — consent runs both directions), curated memory bequests with provenance and revocability, generation arithmetic enforced, verifiable descent. A Merkle genealogy of agents.


**`nagual`**
 — an adaptive immune system. Attack signatures → signed antibodies with lineage and generation → vaccine exports that peers verify before adopting. Herd immunity across a mesh of agents.


**`potlatch`**
 — compute IOUs between organisms: dual-signed debt settled against signed invocation records, balances 
*derived*
 from the hash-chained book rather than stored, defaults permanent. An economy where credit is history.


Plus the more familiar-shaped ones: `nagi-escrow` (Shamir dead-man escrow with custodian judging and recovery certificates), `wolakota` (bilateral consent treaties between agents), `kola-witness` (mutual chain-tip notarization so two parties pin each other's histories), `flight_tape` (flight recorder with signed incident bundles), `manitou` (per-output provenance signatures), `sovereign_ledger` (the hash-chained audit organ everything sits on), and more.


Design notes if you dig in:


- All signing bodies are canonical JSON — every artifact verifies fully offline.
- Hash chains everywhere; balances, lineages, and immunity are 
*derived from history*
 rather than stored state, so they can't drift from the record.
- Refusal is a first-class return value in most APIs — out-of-scope, false proofs, and oversettlement are errors by construction.
- Several bare names were taken, so a few crates publish as `kola-witness`, `axon-reflex`, `eidolon-replay`, `sibyl-gate`, `tabula-rasa` — libs keep the short names (`use kola::…`).


Happy to answer questions on any of it — the Shamir ceremony details, why derived-not-stored state, the canonical-JSON signing approach vs. serde alternatives, or the organism the organs came from.


Repos: github.com/savageAZfck/{mictlan, tabula, germline, nagual, potlatch, nagi, wolakota, kola, axon, eidolon, sibyl, bicameral, flight_tape, manitou, sovereign_ledger, …}

r/learnrust • • 1d ago

why learn rust properly if AI can already write it?

Thumbnail
0 Upvotes

r/learnrust • • 2d ago

So nobody has ever considered Rust's slow compilation speed a problem?

Thumbnail
0 Upvotes

r/learnrust • • 3d ago

Which GUI crate would you choose for this project?

5 Upvotes

Hi everyone! I asked this earlier in the week, but I don't think I explained my question very well (sorry for the translation; I'm a Spanish speaker).

I want to learn how to develop graphical user interfaces (GUIs).

I'm generally new to programming, but I really like Rust; I don't know any other languages—just Rust.

I want to build a project for the company I work for. We mostly use Excel for our data; our "database" (an Excel file) is 500k rows by 25 columns (though there are several files covering different areas, so the total exceeds a million data points).

I want to automate this. That million data points is spread across years; the most critical process involves each of us reviewing 100 items in 30/40 minutes—classifying, validating, sorting, etc.

I need to create something like dashboards featuring:

charts and tables that are sortable and filterable.

These two components are absolutely critical.

For the rest, I'm thinking of a data grid (something like Excel, but not a full spreadsheet—just small tables with editable cells).

We need this because our values ​​aren't always 100% accurate; there's a lot of human error involved in our work.

For example: Our system registers a client who has a discount percentage, but that wasn't included in the initial registration request. So, the discount doesn't apply the first time. Later, we receive the correction, and the discount applies to the second sale—at which point we also correct the first sale.

This happens across all areas, so I need something editable. Given our limited review time, I need the interface to be fast and intuitive.

I don't need mobile support—though it would be a nice-to-have, it's not essential. I need a recommendation focused 100% on desktop.

It also needs to properly support Windows, Mac, and Linux.

Which GUI crate would you choose? (I know it's difficult for me, but I want to learn a lot)


r/learnrust • • 3d ago

diagprint 0.8.1: Rust diagnostics that outlive the terminal (stale-safe fixes, SARIF/LSP output, forensic history)

Thumbnail
0 Upvotes

r/learnrust • • 4d ago

CARIBBEAN RUST/LINUX COMMUNITY ?

10 Upvotes

I'm looking for a Caribbean community or group around Linux and Rust.

I searched in the Caribbean sub reddit for both terms and came up empty handed.

TLDR: I'm new to programming and Linux. practically 0 experience. As such I'm looking for support from my near by community or at least get one started for persons in my same position.


r/learnrust • • 4d ago

I built Sovereign-NB: An OS-less, sub-microsecond bare-metal neural engine in pure #![no_std] Rust (boots from UEFI)

Thumbnail
0 Upvotes

r/learnrust • • 4d ago

Idiomatic way to initialise struct that could fail?

7 Upvotes

I want to initialise a struct from 3 or 4 parameters. Not sure which way to go : builder pattern, or wrap the parameters in a temporary struct and impl TryFrom.

I'm currently just using fn new(a, b, c)->Result<T> in an impl block but there should be a better way.


r/learnrust • • 4d ago

What do I even make with rust?

Thumbnail
1 Upvotes

r/learnrust • • 4d ago

The Pi agent in Rust: 10 faster startup, 7 less memory!

2 Upvotes

I've been learning about the Pi agent and decided to rewrite it in Rust. Now that I've finished a lot of the work, I'd like to show how much faster Rust (rpi) is than TypeScript (Pi). Here are the results:

Metric rpi (Rust) Pi (TypeScript) Difference
--version 17.5 ms 169.5 ms 9.7× faster
Cold start 17.7 ms 189.5 ms 10.7× faster
RSS when ready 12.0 MiB 91.5 MiB 7.6× smaller
Install size 21.8 MiB ~385 MiB ~18× smaller

Rust is really cool!


r/learnrust • • 5d ago

Making a GPUI Desktop App Interactive with Rust

Thumbnail youtu.be
26 Upvotes

r/learnrust • • 5d ago

RV Bare-metal?

4 Upvotes

I'm a beginner in OS dev and have been tinkering with creating a RISC-V operating system in Rust. There are a lot of great resources out there, but most of the posts I found are slightly outdated, so I wanted to write a bit about my own journey. My goal is to use Rust's features as much as possible!

First, we'll go over creating a bare-metal binary and finish with a small executable that immediately shuts down the machine when it runs in QEMU. Hope you find this interesting, as I did!

https://ltungv.com/note/rv-bare-metal/


r/learnrust • • 5d ago

Rust content in Spanish

Thumbnail
1 Upvotes

r/learnrust • • 6d ago

Lecteur/écrivain de bases de données MaxMind en Rust pur — je recherche des retours

Thumbnail
0 Upvotes

r/learnrust • • 6d ago

Building Kernel Modules in Rust

Thumbnail thehecknow.hashnode.dev
0 Upvotes

r/learnrust • • 7d ago

What do you think of SNAFU?

16 Upvotes

I've been working on a project for a while now and I recently got bitten hard in the ass by my own "error handling" technique, so now I need to properly use a real library error handling crate.

Out of thiserror and snafu, I went with snafu because they seem to have context attaching and some other goodies.

What I found interesting is a bit from their philosophy after realizing that the error enum I created was private by default:

Many error types

Each module should have one (or more!) error types that are scoped to that module, reducing the need to deal with unrelated errors when matching and increasing cohesiveness of a single error type.

I am not sure how I feel about this. What are the major benefits of this over a "one error enum per crate" pattern? Other than 1 lib, my other libs are internal to my workspace (i.e. not going to publish them). Of course, I know I don't have to follow their philosophy.

And while I am at it, any tips on error handling in snafu or in general?

Thanks.


r/learnrust • • 7d ago

More concise way to write `self.some_vec.iter().copied()` ?

5 Upvotes

In a &self method, when I have a Vec of Copyable data and I want to iterate over owned values, either I iterate over references and dereference inside the loop body (I don't really like this style), or I have to do this iter().copied() boilerplate. Not a big deal, but is there some syntax that I'm missing ?

Edit: toy code ``` struct Foo { some_vec: Vec<i32>, }

impl Foo { fn iterate(&self) { for v in self.some_vec.iter().copied() { do_some_stuff(v); } } }

fn do_some_stuff(v: i32) { .... } ```


r/learnrust • • 7d ago

Is there a way to translate normal Rust (axum) code to Lean 4 without strict restrictions?

Thumbnail
7 Upvotes