Rust

Cargo & Ecosystem

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

18 câu hỏi phỏng vấn·
Mid-Level
1

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

Câu trả lời

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?

Câu trả lời

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?

Câu trả lời

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 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í