3 ms·
I rarely use lifetimes and I don't deeply copy everything. This tool is probably the fastest in its class - does this code look like having a lot of lifetimes,
by pkolaczk 3y ago
I rarely use lifetimes and I don't deeply copy everything.
This tool is probably the fastest in its class - does this code look like having a lot of lifetimes, cryptic syntax or deep copying?
- https://github.com/pkolaczk/latte/blob/main/src/main.rs https://github.com/pkolaczk/latte/blob/main/src/main.rs
- https://github.com/pkolaczk/latte/blob/main/src/exec.rs https://github.com/pkolaczk/latte/blob/main/src/exec.rs
There was one fundamental "aha" moment for me when it clicked: move semantics.
Once I learned it, suddenly 99% of stuff became simple (including making async quite nice really, contrary to popular HN beliefs).
- wredue 3y agoYou can cherry pick all you want, although I would generally agree that “top level” executables will most likely bump against lifetimes far less frequently than libraries, frameworks, modules etc. I would also generally agree that a single pass through the official book should mostly be enough to be able to read and understand the op.
- pkolaczk 3y agoTherefore I cited the core of the program as well. It also does a bunch of non trivial async processing there. I’ve written at least two other non-toy Rust programs and I haven’t hit “lifetimes everywhere” problem there either. I guess the most lifetime related problems stem from trying to program the Java/Python/JS style in Rust - from overusing references and indirection. If you model your program as a graph of objects referencing each other then I can imagine you have a hard time in Rust.