Hacker News new | past | comments | ask | show | jobs | submit login

It's a very important topic to understand to be productive in Rust.

My knowledge of C made learning Rust so much harder for me. It's really hard to stop thinking in pointers. While Rust's references are technically implemented as pointers, for the purpose of "fighting with the borrow checker" it makes more sense to think of them as read/write locks for regions of memory.




Yeah, interestingly I think it's hard to understand what is going on with C because `T*` pointers can be used for many things. I found it easier to go to C after doing Rust because I had a deeper understanding of the semantics behind them. Was frustrating though because it never caught my mistakes!


C++ helps more than C for Rust.


This is especially true if you are familiar with the RAII principle in C++.


Yeah, there is a bigger emphasis on it in C++11 and on.


I spent a whole day struggling with a bug because I equated &[T] with *T and thought you could cast one to the other (for interop with C++ code). It took me too long to figure out that &[T] is two words long, but now its obvious. I'm not sure where I thought the "length" part was being stored.


For reference, the proper way to get a *const T from a &[T] is the .as_ptr() method. The way &[T] (and any other type not marked with #[repr(C)]) is laid out is implementation-defined, so accessing its internals isn't recommended.


Me too. I found *&var quite confusing.




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

Search: