3 ms·
My experience is that the borrow checker is not that hard to deal with. There are two ways: - you are a c/c++/low level guy who knows how allocation works very
by datadeft 3y ago
My experience is that the borrow checker is not that hard to deal with. There are two ways:
- you are a c/c++/low level guy who knows how allocation works very well and figure it out
- you are a java/c#/python guy who wants to get going and use clone() a lot
Either way, the performance that you get is worth the troubles.
- pjmlp 3y agoBetter create an editor macro to paste those ".clone()" all over the place. You can get similar performance with any AOT compiled language, even managed ones.
- deleted 3y ago[deleted]
- afavour 3y agoFWIW Rust has the Copy trait which lets you more or less do exactly what you’re asking with no pasting required.
- imor80 3y agoCopy and Clone traits have different semantics. Copy is only for bitwise (and cheap) copies. Clone is for explicit, potentially expensive copies. Also what entails cloning differs from type to type. String, for example, needs to duplicate the pointed to string buffer in the heap, while Arc only increments a reference count.
- afavour 3y agoYes, I know. But in the context of what’s being described here someone getting started with Rust and wanting to avoid issues with lifetimes could very easily be using copy in the way the OP described clone.
- sunshowers 3y agoI think these days we generally just use Copilot/an LLM.