Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I suspect if you're looking at C++ as a viable language for the problems you're solving, you're solving quite different problems from me, so take this with a grain of salt.

What I wanted from Rust was basically a strongly-typed C and more modern tooling. I'm open to more checking than that, depending on what cost it has.

What I'm getting is strong typing and more modern tooling--cargo, for example, is excellent. But the borrow checker is extremely invasive, and `unsafe` doesn't actually make it less invasive. There are a number of cases where I still haven't figured out how to get the compiler to not complain about the lack of a `.clone()`. Borrow semantics are... pretty good, as it's basically enforcing a pattern I use frequently anyway, but the exceptions to that pattern are critical and working around the borrow checker causes more problems than it solves. It's possible I just don't know how to make "the Rust way" more workable, but if that's the case I am having a hard time finding how what "the Rust way" is for the things I'm trying to do.

That said, I can see how Rust is a great tool for what it was originally intended for (writing a browser). That's just not what I'm doing.



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.


> 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: