Rust

Structs & Enums

Struct definition, methods, associated functions, tuple structs, enums, Option, Result

20 câu hỏi phỏng vấn·
Junior
1

What is a struct in Rust?

Câu trả lời

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.

2

How to declare a struct named Point with two fields x and y of type i32?

Câu trả lời

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.

3

What is a tuple struct in Rust?

Câu trả lời

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.

4

How to access the fields of a tuple struct Color(u8, u8, u8)?

5

What is an impl block in Rust?

+17 câu hỏi phỏng vấn

Nắm vững Rust cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí