Re:Reflections on Rust, and the Sand Castle Metaphor
by IshKebab on Friday April 27, 2018 @05:12PM
(#16944370)
Sadly this is my third or fourth Rust foray. Only one was really successful - writing a tool to basically do 'git describe' using libgit2. That was a decent experience. I also tried to write a wrapper around libsoundio - got quite far but eventually gave up because of limitations in the Rust lifetime system, and because of how hard it is to do callbacks.
1. It really helped me to stop trying to force my code to be as pretty as possible the first time around.
2. If you are getting errors about a lifetime not living long enough in a complex expression, it can help to pull some part of it out into a helper let binding.
3. Adding an artificial scope (a curly block in the middle of another block) can be a great way to control the lifetime of a borrow.
4. clone() all the things! This is a major advantage that Rust has over other ball-and-chain languages like Haskell. When you get into a type-tetris situation in Haskell, you just have to find a way out. In Rust you can often just clone() something that you would rather not have to clone() and move on. I love being able to tell the borrow checker to go away while I concentrate on my program logic. Later I can always go back and fix it.