Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Is Zig safer than Unsafe Rust? #119

giscus[bot] Bot announced in Articles
Discussion options

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/

You must be logged in to vote

Replies: 1 comment

Comment options

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.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /