Rust

Structs & Enums

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

20 pytań z rozmów·
Junior
1

What is a struct in Rust?

Odpowiedź

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?

Odpowiedź

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?

Odpowiedź

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 pytań z rozmów

Opanuj Rust na następną rozmowę

Uzyskaj dostęp do wszystkich pytań, flashcards, testów technicznych, ćwiczeń code review i symulatorów rozmów.

Zacznij za darmo