News for hackers. Stuff that matters.
Re:Just Write a Test for It by bsaul on Sunday March 30, 2025 @04:24AM (#43522406)
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 ?

Re:Just Write a Test for It by vrnvu on Sunday March 30, 2025 @04:35AM (#43522471)
Specifying lifetimes and types is mostly used when writing libraries. Writing Rust "as a user" is pretty readable and comfortable.
Re:Just Write a Test for It by bschwindHN on Sunday March 30, 2025 @05:16AM (#43522697)
If 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.

Re:Just Write a Test for It by kobzol on Sunday March 30, 2025 @09:12AM (#43523895)
If 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.