3 ms·
At some point, maybe not immediately, depending on what you're building, you'll have the borrow checker tell you that no, you can't borrow there, or that some c
by dystroy 5y ago
At some point, maybe not immediately, depending on what you're building, you'll have the borrow checker tell you that no, you can't borrow there, or that some construct that you feel safe isn't possible. And it will probably come with a big lot of such errors and you'll have to look for another design pattern.
Until it clicks and starts to be natural, there might be a quite rough period.
Until you know the essential traits, how to find them, and you're used to clauses on generics, you may also have some difficulties making sense of some generic code or making your own generic code work.
- ithkuil 5y agoI've passed that hill behind me and I rarely have to fight the borrow checker. If you're familiar with the ownership model and learn the few scoping quirks that's not that hard. What I find way harder to cope with is the gazillions of type parameters with gazillions of guards, send, sync, clone or not clone, then impl Foo for Bar vs impl Foo for Arc<Bar> etc etc; and tons of features in cargo crates, also in private workspace projects, .... And the compiler slowness oh man the compiler slowness. EDIT: my life improved a bit since I learned about the cargo hakari plugin
- stouset 5y agoTo expand on this, I think one of the biggest challenges of Rust right now is that the borrow checker and compiler enforce constraints at a "tree"-level that are indicative of "forest"-level design issues with your code. Once you learn to construct forests in a way that harmonizes well with these constraints, you'll very rarely run into these kinds of tree-level issues. But there needs to be more in the way of education that helps you understand the types of designs that the compiler is trying to push you towards. You can generally get past things by simply `.unwrap()`ing and `.clone()`ing your way past compiler issues, but reaching for them too often prevents you from ever learning those (important) lessons given the current lack of better alternatives to learning them.
- bko 5y agoFrom the article: > So before you dive, have an overview of the book (or books). Maybe don't read it fully, but make sure to have read all titles so that you know when to come back to it later. Could someone familiar with Solana smart contract development highlight which titles from 'the book' are most relevant? I imagine developing smart contracts is much more scoped down than most rust projects.
- porknubbins 5y agoFrom having attempted to understand Solana contracts they make heavy use of traits and serialization libraries.