3 ms·
I think both points are right. There's times when it's useful and desirable to be specific about lifetimes, and there's also times where it's annoying noise. B
by millstone 6y ago
I think both points are right. There's times when it's useful and desirable to be specific about lifetimes, and there's also times where it's annoying noise.
Bignum arithmetic is an example of the latter. You want to just work with numbers, and in Python you can, but in Rust you must clutter your code with lifetimes and borrows and clones.
Swift's plan to allow gradual, opt-in lifetime annotations seems really interesting, if it works.
- CDSlice 6y agoBignum arithmetic actually is pretty simple in Rust if you use the right library. Rug[0] makes using bignums look almost just like using native numbers through operator overloading. [0] https://crates.io/crates/rug https://crates.io/crates/rug
- millstone 6y agoThe operator overloading is nice but you still get smacked in the face right away by the borrow checker. Simple stuff like this won't compile ("use of moved value"): let a = Integer::from(10); let b = a + a;
- smmalis37 6y agolet b = &a + &a; will work, but I agree it's unfortunate that this is necessary.
- pimeys 6y agoThis would work if `Integer` would implement the `Copy` trait. But I guess that type is heavy enough for it to be too expensive, therefore forcing you to explicitly call `clone()`.
- Measter 6y agoThat `Integer` type can't implement `Copy` because it manages a resource, meaning you can't just do a simple memcpy of the type.