Ownership
๋ชจ๋ ๋ณ์ ๋ฐ์ธ๋ฉ์ ์ ํจํ _๋ฒ์_๋ฅผ ๊ฐ์ผ๋ฉฐ, ๋ฒ์ ๋ฐ์์ ๋ณ์ ์ฌ์ฉ์ ์ค๋ฅ์ ๋๋ค:
All variable bindings have a scope where they are valid and it is an error to use a variable outside its scope:
struct Point(i32, i32); fn main() { { let p = Point(3, 4); println!("x: {}", p.0); } // ์ค์ฝํ ์ข ๋ฃ์ง์ println!("y: {}", p.1); } // main ํจ์์ ์ค์ฝํ ์ข ๋ฃ์ง์
- ์ค์ฝํ๊ฐ ์ข ๋ฃ๋๋ฉด ๋ณ์๋ _์ญ์ _๋๊ณ ๋ฐ์ดํฐ ๋ฉ๋ชจ๋ฆฌ๋ ํด์ ๋ฉ๋๋ค.
- ์๋ฉธ์๋ ์ฌ๊ธฐ(์ค์ฝํ ์ข ๋ฃ์ง์ )์์ ๋ฉ๋ชจ๋ฆฌ ์์์ ํด์ ํฉ๋๋ค.
- ์ด๊ฒ์ ๋๊ณ ๋ณ์๊ฐ ๊ฐ์ _์์ _ํ๋ค๊ณ ํํํฉ๋๋ค.
- At the end of the scope, the variable is dropped and the data is freed.
- A destructor can run here to free up resources.
- We say that the variable owns the value.