# Structs & Enums (Rust) > การกำหนด struct, method, associated function, tuple struct, enum, Option, Result - 20 คำถามสัมภาษณ์ - Junior - [คำถามสัมภาษณ์: Rust](https://sharpskill.dev/th/technologies/rust/interview-questions.md) ## 1. struct ใน Rust คืออะไร? **คำตอบ** struct ใน Rust เป็นชนิดข้อมูลแบบกำหนดเองที่ช่วยให้สามารถจัดกลุ่มค่าที่เกี่ยวข้องหลายค่าไว้ภายใต้ชื่อเดียว มันคล้ายกับ class ในภาษาอื่นแต่ไม่มีการสืบทอด struct เป็นพื้นฐานสำคัญสำหรับการสร้างแบบจำลองข้อมูลที่มีโครงสร้างและใช้กันอย่างแพร่หลายในทุกโปรแกรม Rust ## 2. จะประกาศ struct ชื่อ Point ที่มีสองฟิลด์ x และ y ชนิด i32 ได้อย่างไร? **คำตอบ** ไวยากรณ์สำหรับการประกาศ struct ใน Rust ใช้คีย์เวิร์ด struct ตามด้วยชื่อและฟิลด์ในวงเล็บปีกกา แต่ละฟิลด์ระบุชื่อตามด้วยเครื่องหมายโคลอนและชนิดของมัน ไวยากรณ์นี้เป็นรูปแบบมาตรฐานสำหรับการกำหนด struct ที่มีชื่อใน Rust ## 3. tuple struct ใน Rust คืออะไร? **คำตอบ** tuple struct เป็น struct ที่ฟิลด์ถูกระบุด้วยตำแหน่งแทนที่จะเป็นชื่อ มันถูกประกาศด้วยวงเล็บแทนวงเล็บปีกกาและช่วยให้สร้างชนิดข้อมูลใหม่ที่แตกต่างจาก tuple ได้ tuple struct มีประโยชน์สำหรับการสร้าง newtype หรือเมื่อชื่อฟิลด์จะซ้ำซ้อน ## มีอีก 17 คำถาม - จะเข้าถึงฟิลด์ของ tuple struct Color(u8, u8, u8) ได้อย่างไร? - บล็อก impl ใน Rust คืออะไร? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Rust อื่นๆ - [พื้นฐาน Rust](https://sharpskill.dev/th/technologies/rust/interview-questions/rust-basics.md): 25 คำถาม, Junior - [Ownership & Borrowing](https://sharpskill.dev/th/technologies/rust/interview-questions/ownership-borrowing.md): 22 คำถาม, Junior - [การจัดการข้อผิดพลาด](https://sharpskill.dev/th/technologies/rust/interview-questions/error-handling.md): 18 คำถาม, Junior - [คอลเลกชัน](https://sharpskill.dev/th/technologies/rust/interview-questions/collections.md): 20 คำถาม, Junior - [โมดูลและแพ็กเกจ](https://sharpskill.dev/th/technologies/rust/interview-questions/modules-packages.md): 18 คำถาม, Junior - [Traits](https://sharpskill.dev/th/technologies/rust/interview-questions/traits.md): 22 คำถาม, Mid-Level - [Generics](https://sharpskill.dev/th/technologies/rust/interview-questions/generics.md): 20 คำถาม, Mid-Level - [Lifetimes](https://sharpskill.dev/th/technologies/rust/interview-questions/lifetimes.md): 20 คำถาม, Mid-Level - [Iterators & Closures](https://sharpskill.dev/th/technologies/rust/interview-questions/iterators-closures.md): 22 คำถาม, Mid-Level - [Smart Pointers](https://sharpskill.dev/th/technologies/rust/interview-questions/smart-pointers.md): 22 คำถาม, Mid-Level - [Concurrency Basics](https://sharpskill.dev/th/technologies/rust/interview-questions/concurrency-basics.md): 20 คำถาม, Mid-Level - [async/await](https://sharpskill.dev/th/technologies/rust/interview-questions/async-await.md): 22 คำถาม, Mid-Level - [Testing](https://sharpskill.dev/th/technologies/rust/interview-questions/testing.md): 18 คำถาม, Mid-Level - [Cargo & Ecosystem](https://sharpskill.dev/th/technologies/rust/interview-questions/cargo-ecosystem.md): 18 คำถาม, Mid-Level - [Pattern Matching](https://sharpskill.dev/th/technologies/rust/interview-questions/pattern-matching.md): 18 คำถาม, Mid-Level - [มาโคร](https://sharpskill.dev/th/technologies/rust/interview-questions/macros.md): 20 คำถาม, Mid-Level - [Serde และการ Serialization](https://sharpskill.dev/th/technologies/rust/interview-questions/serde-serialization.md): 20 คำถาม, Mid-Level - [Unsafe Rust](https://sharpskill.dev/th/technologies/rust/interview-questions/unsafe-rust.md): 20 คำถาม, Senior - [Trait ขั้นสูง](https://sharpskill.dev/th/technologies/rust/interview-questions/advanced-traits.md): 22 คำถาม, Senior - [Lifetime ขั้นสูง](https://sharpskill.dev/th/technologies/rust/interview-questions/advanced-lifetimes.md): 20 คำถาม, Senior - [Type System](https://sharpskill.dev/th/technologies/rust/interview-questions/type-system.md): 20 คำถาม, Senior - [Tokio & Async I/O](https://sharpskill.dev/th/technologies/rust/interview-questions/tokio-async.md): 22 คำถาม, Senior - [การเพิ่มประสิทธิภาพ](https://sharpskill.dev/th/technologies/rust/interview-questions/performance-optimization.md): 20 คำถาม, Senior - [Memory Management](https://sharpskill.dev/th/technologies/rust/interview-questions/memory-management.md): 20 คำถาม, Senior - [Web Frameworks](https://sharpskill.dev/th/technologies/rust/interview-questions/web-frameworks.md): 22 คำถาม, Senior - [Database Integration](https://sharpskill.dev/th/technologies/rust/interview-questions/database-integration.md): 20 คำถาม, Senior - [Design Pattern ของ Rust](https://sharpskill.dev/th/technologies/rust/interview-questions/design-patterns.md): 20 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/rust/interview-questions/structs-enums