Hacker News new | ask | show | jobs
by azdle 3452 days ago
I assume they're talking about the fact that basically everyone that learns Rust goes through a period of "fighting the borrow checker". Part of the way that rust ensures memory safety is by preventing you from doing things that it can't prove are safe to do. For people coming from languages like C or C++ they've been able to get away with doing things that are probably unsafe but that work either through luck or very careful planning. But since the borrow checker can't prove that some of these tricks are safe it will just say "no" and fail to compile.

Within a couple weeks you will get the hang of what the borrow checker can actually handle and you'll mostly not have problems except when you are actually making a genuine mistake.

1 comments

Honestly, I found dealing with generics worse than the borrow checker. Since the compiler wants everything to be sized, code that I think should work (i.e. using generics and traits) will sometimes just not compile. In fact - I'm dead in the water facing an issue like that right now. That is, by far, the most frustrating thing in using Rust.
Can you describe the issue? Perhaps someone can help.

I don't know if it helps you or not, but you can specify that a type parameter need not be sized with the ?Sized bound. e.g., The `Path::new` constructor is defined as `fn new<S: AsRef<OsStr> + ?Sized>(s: &S) -> &Path`. This means `S` can, for example, be `str`, which is an unsized type.

Thanks guys - much appreciated. I'm on my mobile in another country, so, can't post a link right now - but I will later tonight when I've WiFi.

BTW - this reaction is why I continue to work with Rust; the community is awesome!

(Dealing with trait objects and generics...less so)

Have you asked for help on one of the various forums? If something is leaving you dead in the water, I'd like to help you fix that.
Just ask for help in IRC or your local Rust community and you'll get help. If you want - post here link to gist.github and I'll try to help.