Semua buku

Profesional

Aplikasi Tentang Pelatih Masuk Mulai membaca

Computer Science · Glosarium

Apa itu Lifetime of a reference?

Dikenal juga sebagai: lifetime (Rust)

Definition 6.10 University Computer Science — Year 2 · Bab 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.
Baca dalam konteks →