January 2019
Beginner to intermediate
554 pages
13h 31m
English
Just like generic type parameters, we can specify multiple lifetimes if we have more than one reference that has different lifetimes. However, it can quickly become hairy when you have to juggle with more than one lifetime in your code. Most of the time, we can get away with just one lifetime in our structs or any of our functions. But there are cases where we'll need more than one lifetime annotations. For example, say we are building a decoder library that can parse binary files according to a schema and a given encoded stream of bytes. We have a Decoder object, which has a reference to a Schema object and a reference to a Reader type. Our Decoder definition will then look something like this:
// multiple_lifetimes.rs ...
Read now
Unlock full access