Tous les livres

Professionnel

Applis À propos Coach Connexion Commencer la lecture

Computer Science · Glossaire

Qu'est-ce que « Lifetime of a reference » ?

Aussi appelé : lifetime (Rust)

Definition 6.10 University Computer Science — Year 2 · Chapitre 6 — Rust: Ownership and Borrowing

The lifetime of a reference, written 'a, is the region of the program in which the reference may be used. It must lie within the lifetime of the object referred to, the span from its creation to its drop or move (the lifetime of an object in Book 3’s sense). A function whose result is a reference names, by lifetime parameters in its signature, the arguments the result may borrow from.

The lifetimes of longest_scope.rs, as vertical bars over its source lines. The result must be valid at the println!, line 7, but it may borrow from b, which is dropped at the end of line 6: no region 'a lies within both, and the program is refused.
The lifetimes of longest_scope.rs, as vertical bars over its source lines. The result must be valid at the println!, line 7, but it may borrow from b, which is dropped at the end of line 6: no region 'a lies within both, and the program is refused.
Lire dans le chapitre →