Hacker News new | ask | show | jobs
by eddd-ddde 807 days ago
Have you tried looking at zig?

Also, unsafe is not meant to ease the borrow checker pains, that's like using void* everywhere in C because you don't know how to type a function pointer. Unsafe is meant for places where rust simply doesn't know better, like reading memory mapped registers.

2 comments

> Have you tried looking at zig?

I have given it a very cursory look, but ultimately it doesn't fit my needs for reasons unrelated to the features of the language. Specifically, I'm releasing my C work under the GPL and would not like to write off the possibility of integrating into GNU. Zig doesn't have a GPL implementation (Rust has one which is committed to reaching maturity).

> Also, unsafe is not meant to ease the borrow checker pains, that's like using void* everywhere in C because you don't know how to type a function pointer. Unsafe is meant for places where rust simply doesn't know better, like reading memory mapped registers.

Eh, one could argue that some of these "Rust simply doesn't know better" situations are often borrow checker pains. But in general, I'd agree that bypassing the borrow checker doesn't seem to be the point of `unsafe` in my limited experience.

But the bigger point I'm trying to make is that there doesn't appear to be any solution to some of the borrow checker issues I've run into. There are things you can do in C, which are strongly related to the reasons I'm using these low-level languages, that appear to be impossible in Rust.

Keep in mind the caveat that I'm new to Rust, so there may be some solution I'm just not aware of.

Yeah I think understand the sort of things you are talking about. Often times we have a "proof" that our code is safe in C. Maybe you are sending a pointer to a thread and then want to read from it at the end of your main thread. _You_ know it is safe because you made an informal contract of when that other thread stops using that pointer, but to Rust? informal is not enough. The hard part is knowing how to formalize all of those contracts. Send, Sync, 'static, all of those are a real pain to understand and know when to use correctly, but when you do it, you are formalizing those contracts. Now you don't just think your contract is held, it is _proven_ by the compiler.