
Structs & Enums
Struct definition, methods, associated functions, tuple structs, enums, Option, Result
1What is a struct in Rust?
What is a struct in Rust?
Jawaban
A struct in Rust is a custom data type that allows grouping multiple related values under a single name. It is similar to classes in other languages but without inheritance. Structs are fundamental for modeling structured data and are widely used throughout any Rust program.
2How to declare a struct named Point with two fields x and y of type i32?
How to declare a struct named Point with two fields x and y of type i32?
Jawaban
The syntax for declaring a struct in Rust uses the struct keyword followed by the name and fields in curly braces. Each field specifies its name followed by a colon and its type. This syntax is the standard form for defining named structs in Rust.
3What is a tuple struct in Rust?
What is a tuple struct in Rust?
Jawaban
A tuple struct is a struct whose fields are identified by position rather than by name. It is declared with parentheses instead of curly braces and allows creating a distinct new type from a tuple. Tuple structs are useful for creating newtypes or when field names would be redundant.
How to access the fields of a tuple struct Color(u8, u8, u8)?
What is an impl block in Rust?
+17 pertanyaan wawancara
Topik wawancara Rust lainnya
Rust Basics
Ownership & Borrowing
Error Handling
Collections
Modules & Packages
Traits
Generics
Lifetimes
Iterators & Closures
Smart Pointers
Concurrency Basics
async/await
Testing
Cargo & Ecosystem
Pattern Matching
Macros
Serde & Serialization
Unsafe Rust
Advanced Traits
Advanced Lifetimes
Type System
Tokio & Async I/O
Performance Optimization
Memory Management
Web Frameworks
Database Integration
Rust Design Patterns
Kuasai Rust untuk wawancara berikutnya
Akses semua pertanyaan, flashcards, tes teknis, latihan code review dan simulator wawancara.
Mulai gratis