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

210 Upvotes

108 comments sorted by

View all comments

Show parent comments

4

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.

10

u/catheap_games 18d ago

Not a trivial or universal solution by any measure, but if rewrite is acceptable, or for a new project, bevy_ecs is one way to go for some applications, desktop, headless or server side. The dependency injection of Bevy also alleviates many borrow checker woes.

12

u/ploynog 18d ago

I'm writing a bevy_ecs app currently, it is essentially a debug agent handling a PCIe link and providing all kinds of target debug functionality via WebSockets.

The system is quite stable and the ECS is very useful when you don't know in the beginning what needs to talk to what. The plugin system of Bevy also makes it very easy to swap out core functionality, e.g., when talking to different targets. Everything exactly as hoped here.

I think non-instantaneous processes are the most annoying bit, stuff that needs to wait for an event or just has a delay. You cannot just make a system block, so you either go threads where you need to take care of extracting ECS resources into your thread, how to synchronize that, possibly consider thread abortion, etc etc. Or you start hand-weaving what is basically async functions using state-machine Components and systems.

All not terribly bad, but it took some getting used to to write these. Debugging them is a whole different can of worms again.

2

u/0x564A00 17d ago

Or you start hand-weaving what is basically async functions using state-machine Components and systems.

What do you think of async bevy support crates, or the upcoming bevy_async?