DEV Community

Anuchit Prasertsang
Anuchit Prasertsang

Posted on

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

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

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

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

Top comments (0)

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay