© Carlo Milanesi 2018
Carlo MilanesiBeginning Rusthttps://doi.org/10.1007/978-1-4842-3468-6_23

23. More About Lifetimes

Carlo Milanesi1 
(1)
Bergamo, Italy
 
In this chapter, you will learn:
  • How to avoid having to write lifetime specifiers for simple free functions and methods, as they are inferred

  • Why lifetime specifiers are needed also for structs, tuple-structs, and enums containing references

  • How to write lifetime specifiers for structs, tuple-structs, and enums

  • Why structs containing references to generic parameters need lifetime bounds

Lifetime Elision

In the previous chapter, we saw that every function signature must specify, for each returned reference, whether that reference has a static lifetime or otherwise to which function arguments its lifetime ...

Get Beginning Rust: From Novice to Professional now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.