
Cargo & Ecosystem
Cargo commands, dependencies, features, build scripts, workspaces, crates.io, documentation
1Which Cargo command compiles a project without creating a final executable?
Which Cargo command compiles a project without creating a final executable?
답변
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.
2How to specify a dependency with a minimum version of 1.2.0 but less than 2.0.0 in Cargo.toml?
How to specify a dependency with a minimum version of 1.2.0 but less than 2.0.0 in Cargo.toml?
답변
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.
3What is the role of the Cargo.lock file in a Rust project?
What is the role of the Cargo.lock file in a Rust project?
답변
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.
How to define an optional feature in Cargo.toml?
What is the purpose of the build.rs file at the root of a Cargo project?
+15 면접 질문