Cargo.toml को समझना
Cargo.toml आपके project का ID card है, इसका नाम, version, और बाकी सब कुछ जिस पर यह depend करता है list करते हुए।[package]
name = "name"
version = "0.1.0"
edition = "2021"
[dependencies]
crate_name = "1.0"
The Package Section
Cargo.toml का [package] section आपके project का नाम, version, और इसके target किए Rust edition को record करता है, crate की core identity बनाते हुए।
उदाहरण: The Package Section
[package]
name = "my_project"
version = "0.1.0"
edition = "2021"
⚠️ Run this in your own terminal or Node.js environment.
The Dependencies Section
[dependencies] section आपके project को चाहिए external crates list करता है, version requirements के साथ जिन्हें Cargo compatible versions resolve करने के लिए उपयोग करता है।
उदाहरण: The Dependencies Section
[dependencies]
serde = "1.0"
rand = "0.8"
⚠️ Run this in your own terminal or Node.js environment.
Cargo.toml vs Cargo.lock
जबकि आप यह declare करने के लिए Cargo.toml को हाथ से edit करते हैं कि आप किस पर depend करते हैं, Cargo अपने आप Cargo.lock generate और maintain करता है, एक reproducible build के लिए असल में resolve और उपयोग किए गए exact versions record करते हुए।
उदाहरण: Cargo.toml vs Cargo.lock
// Entry point: execution of the program starts here
fn main() {
// Print "Cargo.toml: what you declare" to the console (with a trailing newline)
println!("Cargo.toml: what you declare");
// Print "Cargo.lock: what was actually resolved and locked in" to the console (with a trailing newline)
println!("Cargo.lock: what was actually resolved and locked in");
}
Login to try C/C++/Java/PHP code in the editor
Rust Editions
edition field Cargo को आपके code को language rules के एक specific set (जैसे 2015, 2018, या 2021) के खिलाफ compile करने देता है, language को evolve होने देते हुए जबकि पुराना code बिना बदले compile होता रहे।
उदाहरण: Rust Editions
// Entry point: execution of the program starts here
fn main() {
// Declare an immutable variable `editions`, set to `["2015", "2018", "2021"]`
let editions = ["2015", "2018", "2021"];
// Loop over `editions.iter()`, binding each item to `e`
for e in editions.iter() {
// Print "Rust edition: {}" to the console, substituting in `e` (with a trailing newline)
println!("Rust edition: {}", e);
}
}
Login to try C/C++/Java/PHP code in the editor
[dependencies]section को एक गलत version format के साथ edit करना, जोcargo buildको dependencies resolve करने में fail कराता है।Cargo.toml(manifest जो आप हाथ से edit करते हैं) कोCargo.lock(exact resolved versions, आमतौर पर auto-managed) के साथ confuse करना।- crates.io पर एक updated crate publish करने से पहले
versionfield bump करना भूल जाना।
Cargo.tomlmanifest file है जो किसी project के metadata, edition, और dependencies describe करती है।[package]section नाम, version, और edition रखता है;[dependencies]external crates list करता है।Cargo.lockexact resolved dependency versions record करता है और आमतौर पर binaries के लिए commit किया जाता है, Cargo द्वारा auto-generated।- Editions (जैसे
2021) Rust को समय के साथ syntax/semantics evolve करने देते हैं बिना पुराने projects को तोड़े।
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: