Rust

Structs & Enums

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

20 면접 질문·
Junior
1

What is a struct in Rust?

답변

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?

답변

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?

답변

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 면접 질문

다음 면접을 위해 Rust을 마스터하세요

모든 질문, flashcards, 기술 테스트, 코드 리뷰 연습, 면접 시뮬레이터에 접근하세요.

무료로 시작하기