tezvyn:

Rust lifetimes versus Go garbage-collected lifetimes

Source: interviewintermediate

WHAT IT TESTS: understanding of how Rust tracks reference validity. OUTLINE: a lifetime is a compile-time region a reference is valid for; annotations like 'a relate input and output reference durations; Go instead uses garbage collection and escape analysis.

WHAT IT TESTS: whether you grasp that lifetimes are purely compile-time annotations describing how long references stay valid. ANSWER OUTLINE: A lifetime names a region of code over which a reference is guaranteed valid; generic lifetime parameters let a function express that an output reference borrows from an input. Example: fn longest<'a>(x: &'a str, y: &'a str) -> &'a str ties the returned reference's validity to both inputs. Without it the compiler cannot verify the result does not outlive its source.

Read the original → interview

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Rust lifetimes versus Go garbage-collected lifetimes · Tezvyn