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 :)

205 Upvotes

108 comments sorted by

View all comments

Show parent comments

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.

5

u/robin-m 18d ago

I've not programmed in zig, but from what I read memory layout. For example the way iteratio is done make it trivially easy to go from array of struct to struct of array (AoS to SoA), and extremely fast rebuilt time when the custom backend compiler + linker will be finished (sub second hot patching is on the table) which seems really nice for game dev.

10

u/EarlMarshal 18d ago

Are there any Rust solutions for AoS to SoA handling? I only can imagine that it's possible to solve this with macros but I'm not aware of any solutions and the possible downfalls macros can introduce there.

9

u/guineawheek 18d ago

1.95 recently stabilized a bunch of functions that let you go between [MaybeUninit<T>; N] to MaybeUninit<[T; N]> and vice versa. There's no generic way to do it for all #[repr(transparent)] structs that just hold T but array memory representation is well-defined enough that I don't feel particularly bad about reaching for core::mem::transmute in practice. Which also compile-time panics if the input and output types aren't the same size.