Rust

Cargo & Ecosystem

Cargo commands, dependencies, features, build scripts, workspaces, crates.io, documentation

18 domande da colloquioยท
Mid-Level
1

Which Cargo command compiles a project without creating a final executable?

Risposta

The cargo check command compiles the code to verify errors without producing a final binary. This command is much faster than cargo build because it skips the machine code generation step. It is ideal during development to quickly validate that the code compiles correctly.

2

How to specify a dependency with a minimum version of 1.2.0 but less than 2.0.0 in Cargo.toml?

Risposta

The serde = "1.2" syntax uses Cargo's default semantic versioning. It means Cargo will accept any version compatible with 1.2.0, i.e., >= 1.2.0 and < 2.0.0. This notation is equivalent to serde = "^1.2" and is the idiomatic way to specify dependencies in Rust.

3

What is the role of the Cargo.lock file in a Rust project?

Risposta

The Cargo.lock file records the exact versions of all dependencies used during the last successful compilation. This ensures reproducible builds by using exactly the same versions across different machines. For libraries, this file is typically ignored in git, but for binaries and applications, it should be versioned.

4

How to define an optional feature in Cargo.toml?

5

What is the purpose of the build.rs file at the root of a Cargo project?

+15 domande da colloquio

Padroneggia Rust per il tuo prossimo colloquio

Accedi a tutte le domande, flashcards, test tecnici, esercizi di code review e simulatori di colloquio.

Inizia gratis