-
-
Notifications
You must be signed in to change notification settings - Fork 43
Is Zig safer than Unsafe Rust? #119
-
Is Zig safer than Unsafe Rust?
Recently, a hotly debated post trending on Reddit: When Zig is safer and faster than Rust. Although the title says Rust, it's actually comparing with Unsafe Rust. Based on that post, I’d like to discu
https://rustmagazine.org/issue-3/is-zig-safer-than-unsafe-rust/
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 2
Replies: 1 comment
-
Thanks for share.
For the array example, I think the author's main idea is we cannot have another reference beside a mutable reference.
let values: &mut [Value] = std::slice::from_raw_parts_mut(values, len); // I can use the ergonomics of iterators! for val in values.iter_mut() { // ... // Perform actions on each `val` of type &mut Value val.0 += 1; } let values2: &mut [Value] = std::slice::from_raw_parts_mut(values, len);
When we define value2, the whole block is UB since we don't know what compiler will do in this case.
Beta Was this translation helpful? Give feedback.
All reactions
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment