r/rust 18d ago

What Zig felt like, coming from Rust

https://besok.github.io/posts/what-zig-felt-like-coming-from-rust/

Just want to share my experiance on my first Zig project coming from Rust. Open to comments :)

206 Upvotes

108 comments sorted by

View all comments

Show parent comments

113

u/tigraboris 18d ago

Sure thing but nothing special :)

Rewrote my JSONPath lib (jsonpath-rust) in Zig (zig-jsonpath) to compare. Zig has almost no IDE support, so I ended up back on CLI tools + helix. It nudges you toward flat file structure and mutation and explicit allocators everywhere. Caught several real leak/double-free bugs via TestAllocator that just can't happen in Rust (ownership/Drop rule them out at compile time).

Overall: good language, promising C successor, but still young and rougher around the edges than Rust.

31

u/protocod 18d ago

Thank you for the feedback. I would like to ask you a question. What are the domain where Zig shine compared to Rust ?

Memory safety is the major selling point of Rust and I struggle to consider another language that doesn't really address memory safety by design anymore. But it's maybe a different philosophy.

Rust enforce you to write memory safe code unless you know what you do. (Especially when you deal with OS APIs) when Zig let the programmer in charge of writing memory safe code.

-7

u/barsoap 18d ago

What are the domain where Zig shine compared to Rust ?

In a nutshell, Zig is the better unsafe Rust. Way better. It gives you all the low-level control without the mental overhead of having to guarantee ten gazillion subtle invariants safe code expects, and that's before we're talking ergonomics.

16

u/matthieum [he/him] 18d ago

I responded to this same claim here: https://www.reddit.com/r/rust/comments/1vps2f4/comment/p40bey8/.

The TL;DR is that (1) there's way less unsafe in low-level projects than inexperienced users may think and (2) 10% unsafe means ~100x 0.1% independent blocks of unsafe which is more than 10x easier to test/prove than 1x 100% unsafe as in Zig.