3 ms·
I know Rust much better than Zig. I found that one difference between the two is Zig default behavior on mem alloc: it can fail. All code alloc'ing mem needs t
by cies 6y ago
I know Rust much better than Zig. I found that one difference between the two is Zig default behavior on mem alloc: it can fail.
All code alloc'ing mem needs to deal with this potential failing: the dev can choose to "panic/die/exit/etc" or possibly a different strategy can be chosen (display smth in the UI, not allocating memory, etc).
Rust has this "nicely return a Result, instead of exceptions/panics/etc", in most cases, but not in the case of mem alloc. That a big difference between Zig an Rust.
Now Rust has alternative methods for mem alloc that return a Result: but these are not the default and thus hard to discover. This is "unsafe behavior by default" in Rust. This is special, as Rust usually promotes the safe path.