Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

บทที่ 6: Structs - โครงสร้างข้อมูล

Struct ช่วยให้เราสร้าง custom data type ที่รวมข้อมูลหลายชิ้นไว้ด้วยกัน


สิ่งที่จะได้เรียนรู้

หัวข้อคำอธิบาย
การสร้าง Structกำหนดโครงสร้างข้อมูล
Methodsฟังก์ชันที่ผูกกับ struct
Associated Functionsฟังก์ชันที่เกี่ยวข้องกับ struct

ทำไมต้องใช้ Struct?

แทนที่จะเขียนแบบนี้:

#![allow(unused)]
fn main() {
let user_name = "Alice";
let user_email = "alice@example.com";
let user_age = 25;
}

ใช้ Struct รวมข้อมูลที่เกี่ยวข้องกัน:

#![allow(unused)]
fn main() {
struct User {
    name: String,
    email: String,
    age: u32,
}
}

เริ่มกันเลย!

👉 การสร้าง Struct