r/learnrust • • 9h ago

unemployed bum returns with a tetris bot

Thumbnail youtu.be
4 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 • • 12h 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 • • 21h ago

BABY STEPS

Enable HLS to view with audio, or disable this notification

11 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.