Todos los libros

Profesional

Apps Acerca de Coach Iniciar sesión Empezar a leer

Computer Science · Glosario

¿Qué es Lifetime of a reference?

También llamado: lifetime (Rust)

Definition 6.10 University Computer Science — Year 2 · Capítulo 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.
Leer en el capítulo →