Comment

Comment by steveklabnik

We put this aside in the book for this exact reason: https://doc.rust-lang.org/stable/book/ch12-03-improving-erro...

> But I felt like if I could have worked out borrowing it would've generated more efficient code and less memory consumption.

That is possible! But while you're learning, this isn't the most important thing to focus on. And depending on what you're trying to do, using borrowing may be easy, or may be hard, and while you're trying to learn, you don't know enough to evaluate the tradeoff on that basis, so in my humble opinion, it is absolutely okay to clone, and is probably even what you should do in most cases.

Once you're feeling good enough about Rust to start digging deeper, working on trying to not do this is a valuable skill. But imho it's a waste of time when you're starting, and may lead you into a pit of despair.

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton