Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can be an owner?

Tags:

rust

ownership

The Rust book states:

Each value in Rust has an owner

It does not explain what type of entity this owner is. Is it a programmer? a variable? A statement? A code block?

What is the precise definition of what type of entity can be a 'value owner'?

like image 986
Ari Fordsham Avatar asked Oct 17 '25 00:10

Ari Fordsham


1 Answers

Usually, owners are variables or fields; they are responsible for dropping the value owned. However, more surprisingly, even the program binary can be an owner too. As an example, that's the case for string literals:

let s = "Hello World";

The string literal above is stored in the program binary itself, s is just a reference to it. As such, its lifetime is 'static, i.e., the literal lifespan corresponds to the program execution.

like image 151
ネロク・ゴ Avatar answered Oct 19 '25 17:10

ネロク・ゴ