[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"academy-blogs-th-1-1-all-rust-series-ep5-data-types-all--*":3,"academy-blog-translations-6fihd4eoshq37wa":86},{"data":4,"page":85,"perPage":85,"totalItems":85,"totalPages":85},[5],{"alt":6,"collectionId":7,"collectionName":8,"content":9,"cover_image":10,"cover_image_path":11,"created":12,"created_by":13,"expand":14,"id":78,"keywords":79,"locale":54,"published_at":80,"scheduled_at":13,"school_blog":76,"short_description":81,"slug":82,"status":74,"title":83,"updated":84,"updated_by":13,"views":77},"ภาพกราฟิกสรุปชนิดข้อมูลในภาษา Rust แบ่งออกเป็นกลุ่ม Scalar และ Compound พร้อมตัวอย่าง Syntax การประกาศตัวแปร","sclblg987654321","school_blog_translations","\u003Cp>ใน EP.4 เราได้รู้วิธีประกาศตัวแปรกันไปแล้ว แต่สิ่งที่มาคู่กับตัวแปรเสมอคือ \u003Cstrong>\"ชนิดของข้อมูล\" (Data Types)\u003C\u002Fstrong> ครับ ใน Rust ข้อมูลทุกอย่างจะต้องมีประเภทที่ชัดเจนเพื่อให้ Compiler มั่นใจว่าโปรแกรมจะทำงานได้อย่างปลอดภัย\u003C\u002Fp>\u003Cp>เราสามารถแบ่ง Data Types ใน Rust ออกเป็น 2 กลุ่มใหญ่ คือ \u003Cstrong>Scalar\u003C\u002Fstrong> (ค่าเดี่ยว) และ \u003Cstrong>Compound\u003C\u002Fstrong> (ค่ากลุ่ม)\u003C\u002Fp>\u003Ch2>1. Scalar Types (ประเภทข้อมูลค่าเดี่ยว)\u003C\u002Fh2>\u003Cp>Scalar คือชนิดข้อมูลที่เก็บ \"ค่าเดียว\" ในตัวมันเอง มีอยู่ 4 ประเภทหลัก:\u003C\u002Fp>\u003Ch3>🔢 Integers (จำนวนเต็ม)\u003C\u002Fh3>\u003Cp>Rust มีจำนวนเต็มให้เลือกใช้ตามขนาดหน่วยความจำ (bits) แบ่งเป็นแบบมีเครื่องหมาย (\u003Ccode>i\u003C\u002Fcode>) และไม่มีเครื่องหมาย (\u003Ccode>u\u003C\u002Fcode>):\u003C\u002Fp>\u003Ctable style=\"min-width: 75px;\">\u003Ccolgroup>\u003Ccol style=\"min-width: 25px;\">\u003Ccol style=\"min-width: 25px;\">\u003Ccol style=\"min-width: 25px;\">\u003C\u002Fcolgroup>\u003Ctbody>\u003Ctr>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Cstrong>Length\u003C\u002Fstrong>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Cstrong>Signed\u003C\u002Fstrong>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Cstrong>Unsigned\u003C\u002Fstrong>\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>8-bit\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Ccode>i8\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Ccode>u8\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>32-bit\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Ccode>i32\u003C\u002Fcode> (Default)\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Ccode>u32\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>64-bit\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Ccode>i64\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Ccode>u64\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003Ctr>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>arch\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Ccode>isize\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Ftd>\u003Ctd colspan=\"1\" rowspan=\"1\">\u003Cp>\u003Ccode>usize\u003C\u002Fcode>\u003C\u002Fp>\u003C\u002Ftd>\u003C\u002Ftr>\u003C\u002Ftbody>\u003C\u002Ftable>\u003Cblockquote>\u003Cp>\u003Cstrong>Note:\u003C\u002Fstrong> \u003Ccode>isize\u003C\u002Fcode> และ \u003Ccode>usize\u003C\u002Fcode> จะเปลี่ยนขนาดตามสถาปัตยกรรมคอมพิวเตอร์ที่คุณใช้ (เช่น 64-bit บน Mac M4) มักใช้ในการระบุ Index ของ Array ครับ\u003C\u002Fp>\u003C\u002Fblockquote>\u003Ch3>🥧 Floating-Point (ทศนิยม)\u003C\u002Fh3>\u003Cp>มี 2 ขนาดคือ \u003Ccode>f32\u003C\u002Fcode> และ \u003Ccode>f64\u003C\u002Fcode> (Default)\u003C\u002Fp>\u003Cp>Rust\u003C\u002Fp>\u003Cpre>\u003Ccode>let x = 2.0; \u002F\u002F f64 โดยอัตโนมัติ\nlet y: f32 = 3.0; \u002F\u002F ประกาศแบบระบุ f32\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3>✅ Booleans (ตรรกศาสตร์)\u003C\u002Fh3>\u003Cp>มีแค่สองค่าคือ \u003Ccode>true\u003C\u002Fcode> และ \u003Ccode>false\u003C\u002Fcode> ใช้พื้นที่ 1 Byte\u003C\u002Fp>\u003Cp>Rust\u003C\u002Fp>\u003Cpre>\u003Ccode>let is_active = true;\nlet is_finished: bool = false;\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3>🔤 Characters (ตัวอักษร)\u003C\u002Fh3>\u003Cp>ใน Rust \u003Ccode>char\u003C\u002Fcode> จะใช้ Single Quotes (\u003Ccode>'\u003C\u002Fcode>) และมีขนาด \u003Cstrong>4 Bytes\u003C\u002Fstrong> เพราะมันเก็บค่า \u003Cstrong>Unicode Scalar Value\u003C\u002Fstrong> หมายความว่ามันเก็บได้มากกว่าตัวอักษรภาษาอังกฤษ (รวมถึง Emoji และภาษาไทยด้วย!)\u003C\u002Fp>\u003Cp>Rust\u003C\u002Fp>\u003Cpre>\u003Ccode>let c = 'z';\nlet heart_eye_emoji = '😻';\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch2>2. Compound Types (ประเภทข้อมูลแบบกลุ่ม)\u003C\u002Fh2>\u003Cp>Compound คือการนำหลายๆ ค่ามารวมกันไว้ในตัวแปรเดียว มี 2 ประเภทหลัก:\u003C\u002Fp>\u003Ch3>📦 Tuples\u003C\u002Fh3>\u003Cp>ใช้เก็บค่าหลายประเภทมารวมกัน แต่ \u003Cstrong>\"ขนาดต้องคงที่\"\u003C\u002Fstrong> (เพิ่ม\u002Fลดไม่ได้หลังจากประกาศ)\u003C\u002Fp>\u003Cp>Rust\u003C\u002Fp>\u003Cpre>\u003Ccode>let person: (&amp;str, i32, bool) = (\"Ploy\", 25, true);\n\n\u002F\u002F การดึงค่าออกมา (Destructuring)\nlet (name, age, status) = person;\n\n\u002F\u002F หรือดึงผ่าน Index\nlet name = person.0;\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Ch3>🔢 Arrays\u003C\u002Fh3>\u003Cp>ใช้เก็บค่า \u003Cstrong>\"ประเภทเดียวกันเท่านั้น\"\u003C\u002Fstrong> และมี \u003Cstrong>\"ขนาดที่แน่นอน\"\u003C\u002Fstrong> เก็บข้อมูลไว้ใน Stack ซึ่งทำให้ทำงานได้เร็วมาก\u003C\u002Fp>\u003Cp>Rust\u003C\u002Fp>\u003Cpre>\u003Ccode>let months = [\"Jan\", \"Feb\", \"Mar\"];\nlet numbers: [i32; 5] = [1, 2, 3, 4, 5]; \u002F\u002F [Type; Length]\n\n\u002F\u002F การดึงค่า\nlet first = numbers[0];\n\u003C\u002Fcode>\u003C\u002Fpre>\u003Cblockquote>\u003Cp>\u003Cstrong>ข้อควรระวัง:\u003C\u002Fstrong> ถ้าคุณพยายามดึงข้อมูลเกิน Index ที่มี (Out of bounds) Rust จะทำให้โปรแกรม \"Panic\" (หยุดทำงาน) ทันทีเพื่อความปลอดภัยครับ\u003C\u002Fp>\u003C\u002Fblockquote>\u003Cp>\u003C\u002Fp>\u003Cdiv data-type=\"horizontalRule\">\u003Chr>\u003C\u002Fdiv>\u003Ch2>สรุป\u003C\u002Fh2>\u003Cp>การเลือกใช้ Type ที่เหมาะสมไม่เพียงแต่ช่วยประหยัด Memory แต่ยังช่วยให้ Compiler ของ Rust เป็น \"ผู้ช่วย\" ตรวจสอบความถูกต้องของ Logic ให้เราได้ด้วย\u003C\u002Fp>\u003Cp>ใน \u003Cstrong>EP.6\u003C\u002Fstrong> เตรียมตัวพบกับเรื่อง \u003Cstrong>Control Flow\u003C\u002Fstrong> เราจะไปดูวิธีการใช้ \u003Ccode>if-else\u003C\u002Fcode> และการวนลูปรูปแบบต่างๆ เพื่อให้โปรแกรมของเราทำงานได้หลากหลายเงื่อนไขมากขึ้นครับ!\u003C\u002Fp>\u003Ch2>🎯 ติดตามความรู้สาย Dev แบบสุดจัดได้ที่:\u003C\u002Fh2>\u003Cp>ไม่อยากพลาดบทความเทคนิคเชิงลึกและอัปเดตใหม่ๆ จากเรา ติดตาม \u003Cstrong>Superdev Academy\u003C\u002Fstrong> ได้ทุกช่องทางที่นี่ครับ:\u003C\u002Fp>\u003Cul>\u003Cli>\u003Cp>🔵 \u003Cstrong>Facebook:\u003C\u002Fstrong> \u003Ca target=\"_blank\" rel=\"noopener\" class=\"ng-star-inserted\" href=\"https:\u002F\u002Fwww.facebook.com\u002Fsuperdev.academy.th\">Superdev Academy Thailand\u003C\u002Fa> (อัปเดตข่าวสารและบทความใหม่)\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>🎬 \u003Cstrong>YouTube:\u003C\u002Fstrong> \u003Ca target=\"_blank\" rel=\"noopener\" class=\"ng-star-inserted\" href=\"https:\u002F\u002Fwww.youtube.com\u002F@SuperdevAcademy\">Superdev Academy Channel\u003C\u002Fa> (ติวเข้มแบบวิดีโอ)\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>📸 \u003Cstrong>Instagram:\u003C\u002Fstrong> \u003Ca target=\"_blank\" rel=\"noopener\" class=\"ng-star-inserted\" href=\"https:\u002F\u002Fwww.instagram.com\u002Fsuperdevacademy\u002F\">@superdevacademy\u003C\u002Fa> (เกร็ดความรู้สั้นๆ และเบื้องหลังการทำงาน)\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>🎬 \u003Cstrong>TikTok:\u003C\u002Fstrong> \u003Ca target=\"_blank\" rel=\"noopener\" class=\"ng-star-inserted\" href=\"https:\u002F\u002Fwww.tiktok.com\u002F@superdevacademy?lang=th-TH\">@superdevacademy\u003C\u002Fa> (Tips &amp; Tricks ฉบับย่อยง่าย)\u003C\u002Fp>\u003C\u002Fli>\u003Cli>\u003Cp>🌐 \u003Cstrong>Website:\u003C\u002Fstrong> \u003Ca target=\"_blank\" rel=\"noopener noreferrer nofollow\" href=\"http:\u002F\u002Fsuperdevacademy.com\">superdevacademy.com\u003C\u002Fa> (คลังบทความและคอร์สเรียนฉบับเต็ม)\u003C\u002Fp>\u003C\u002Fli>\u003C\u002Ful>\u003Cp>\u003C\u002Fp>","9u16mwgyong_x79z697r1o.png","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclblg987654321\u002Fzyft5pi49frlbwi\u002F9u16mwgyong_x79z697r1o.png","2026-04-03 10:52:09.920Z","",{"keywords":15,"locale":48,"school_blog":58},[16,23,28,33,38,43],{"collectionId":17,"collectionName":18,"created":19,"created_by":13,"id":20,"name":21,"updated":22,"updated_by":13},"sclkey987654321","school_keywords","2026-03-16 05:10:32.092Z","s8r1st4glsmm7yl","ภาษา Rust","2026-04-10 16:14:41.900Z",{"collectionId":17,"collectionName":18,"created":24,"created_by":13,"id":25,"name":26,"updated":27,"updated_by":13},"2026-04-03 10:51:22.578Z","ckgl4w4nk4uirqs","Data Types","2026-04-10 16:14:47.014Z",{"collectionId":17,"collectionName":18,"created":29,"created_by":13,"id":30,"name":31,"updated":32,"updated_by":13},"2026-04-03 10:51:34.251Z","a38yxdu4yv4sp47","Scalar types","2026-04-10 16:14:47.107Z",{"collectionId":17,"collectionName":18,"created":34,"created_by":13,"id":35,"name":36,"updated":37,"updated_by":13},"2026-04-03 10:51:41.429Z","kq299ibv4vo4jth","Compound types","2026-04-10 16:14:47.227Z",{"collectionId":17,"collectionName":18,"created":39,"created_by":13,"id":40,"name":41,"updated":42,"updated_by":13},"2026-03-23 03:08:18.875Z","pu1hva5rmnc4672","สอน Rust","2026-04-10 16:14:44.507Z",{"collectionId":17,"collectionName":18,"created":44,"created_by":13,"id":45,"name":46,"updated":47,"updated_by":13},"2026-03-04 08:44:11.146Z","gms2qr4xg6qv65e","Superdev Academy","2026-04-10 16:12:41.207Z",{"code":49,"collectionId":50,"collectionName":51,"created":52,"flag":53,"id":54,"is_default":55,"label":56,"updated":57},"th","pbc_1989393366","locales","2026-01-22 10:59:55.832Z","twemoji:flag-thailand","s8wri3bt4vgg2ji",true,"Thai","2026-04-10 15:42:46.614Z",{"category":59,"collectionId":60,"collectionName":61,"expand":62,"id":76,"views":77},"mfqe235iv6x1or8","pbc_2105096300","school_blogs",{"category":63},{"blogIds":64,"collectionId":65,"collectionName":66,"created":67,"created_by":13,"id":59,"image":68,"image_alt":13,"image_path":69,"label":70,"name":71,"priority":72,"publish_at":73,"scheduled_at":13,"status":74,"updated":75,"updated_by":13},[],"sclcatblg987654321","school_category_blogs","2026-03-16 04:40:07.104Z","47vt5s1gglj_tz0b90vnge.png","https:\u002F\u002Ftwsme-r2.tumwebsme.com\u002Fsclcatblg987654321\u002Fmfqe235iv6x1or8\u002F47vt5s1gglj_tz0b90vnge.png",{"en":71,"th":71},"Rust The Series",2,"2026-03-16 04:40:09.199Z","published","2026-04-25 02:32:15.619Z","6fihd4eoshq37wa",113,"zyft5pi49frlbwi",[20,25,30,35,40,45],"2026-04-07 02:56:17.019Z","ทำความรู้จักกับ Data Types ในภาษา Rust ตั้งแต่ระดับพื้นฐานอย่างตัวเลขและตัวอักษร ไปจนถึงข้อมูลแบบกลุ่มอย่าง Tuples และ Arrays เพื่อการจัดการหน่วยความจำที่แม่นยำและปลอดภัยตามสไตล์ Superdev Academy","rust-series-ep5-data-types","ชนิดข้อมูลพื้นฐานใน Rust: เจาะลึก Scalar และ Compound types (Integers, Tuples, Arrays) | Rust The Series EP.5","2026-04-22 07:11:54.537Z",1,{"th":82,"en":87},"rust-programming-data-types-guide"]