News for hackers. Stuff that matters.
Re:What Is Rust's Unsafe? (2019) by EE84M3i on Sunday April 10, 2022 @03:44PM (#30980950)
As mentioned in the article, it's entirely possible to create a raw pointer to an object in safe rust, you just can't do much with it. One thing you can do with it though is convert it to an integer and reveal a randomized base address, which isn't possible in some other languages without their "unsafe" features. Of course, this follows naturally from Rust's definition of what is safe, but I remember being kind of surprised by it when I first learned Rust and didn't understand those definitions yet.

It would be pretty interesting to me if someone wrote a survey of what different languages consider to be "unsafe", including specific operations like this. For example, it looks like "sizeof" is relegated to the "unsafe" package in Go, which strikes me as strange.[1] I'd love to read a big comparison.

[1]: https://pkg.go.dev/unsafe#Sizeof

Re:What Is Rust's Unsafe? (2019) by afdbcreid on Sunday April 10, 2022 @11:54PM (#30984457)
I am by no means a Go expert, but I think the `unsafe` package is the only standard library package in Go that does not conform to the stability & portability guarantees and `Sizeof` is neither portable nor stable.
Re:What Is Rust's Unsafe? (2019) by EE84M3i on Monday April 11, 2022 @09:14AM (#30988189)
At the top of the page it says "Package unsafe contains operations that step around the type safety of Go programs." though
Re:What Is Rust's Unsafe? (2019) by afdbcreid on Sunday April 10, 2022 @11:52PM (#30984437)
You can also compare & hash it. I once used it, to store visited objects in a hashset without the borrow checker making me sad.