3 ms·
Sidenote : i found this code quite readable. I'm usually reading Rust code here on HN that's full of weird lifetime annotations or Dyn or super long generic typ
by bsaul 2y ago
Sidenote : i found this code quite readable. I'm usually reading Rust code here on HN that's full of weird lifetime annotations or Dyn or super long generic types. As a non-rust dev this freaked me out.
How common is this kind of code in practice ?
- vrnvu 2y agoSpecifying lifetimes and types is mostly used when writing libraries. Writing Rust "as a user" is pretty readable and comfortable.
- bschwindHN 2y agoIf you're running something like this and it isn't performance sensitive, you don't really need to deal with lifetimes at all. Lifetimes mostly come into play if you want to work with zero-copy parsing, or structs that borrow some things and act like a sub-view into the data you're working with. I'm sure there are plenty of other use cases for lifetimes, but they don't come up very often when writing standard "application" code.
- kobzol 2y agoIf you're writing applications or tests, it's mostly the simpler kind of code. If you're writing reusable (or perf. critical code), you will start seeing generics and lifetimes much more often.