DEV Community

Anuchit Prasertsang
Anuchit Prasertsang

Posted on

Rust | กฎความเป็นเจ้าของ

มีกฎ 3 ข้อ สำหรับความเป็นเจ้าของ (owner) ของข้อมูลในภาษา Rust

  1. ตัวแปรข้อมูลคือ owner ของข้อมูลค่านั้น
  2. ณ เวลาหนึ่งๆ ข้อมูลค่านั้นๆจะมี owner ได้เพียงคนเดียวเท่านั้น
  3. เมื่อตัวแปรหลุดขอบเขตของตัวเองแล้ว ค่าข้อมูลที่ตัวแปรนั้นถืออยู่ก็ถูกลบทิ้งไปด้วย

นั่นคือแนวคิดในการจัดการข้อมูลโดยไม่ต้องใช้ Garbage collector

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay