Cargo Run और Build
cargo build और cargo run सरल commands हैं जो आपके Rust code को एक program में बदल देते हैं और, अगर आप चाहें, इसे तुरंत run कर देते हैं।cargo run [--release] [-- args]
cargo build [--release]
Building a Project
cargo build आपके project को बिना run किए compile करता है। Resulting debug executable target/debug/ में रखी जाती है, और default रूप से यह build debug information include करती है और heavy optimizations skip करती है ताकि compilation खुद तेज़ हो।
उदाहरण: Building a Project
cargo build
⚠️ Run this in your own terminal or Node.js environment.
Running a Project
cargo run एक convenience command है जो आपके project को compile करता है (सिर्फ अगर source files बदली हों) और फिर तुरंत resulting binary execute करता है। यह वह command है जिसे आप development के दौरान सबसे ज़्यादा उपयोग करेंगे।
उदाहरण: Running a Project
cargo run
⚠️ Run this in your own terminal or Node.js environment.
Release Builds
--release पास करना Cargo को compiler optimizations apply करने को कहता है, लंबे compile times की कीमत पर एक छोटी और कहीं ज़्यादा तेज़ binary produce करते हुए। Release builds वही हैं जिन्हें आप production में ship करते हैं या performance benchmarking के लिए उपयोग करते हैं।
उदाहरण: Release Builds
cargo build --release
⚠️ Run this in your own terminal or Node.js environment.
Seeing the Output in Code
चाहे debug में build हो या release mode में, program का logic और output identical हैं -- सिर्फ speed और binary size अलग होते हैं। यह उदाहरण बिल्कुल वही है जो cargo run एक project scaffold करने के बाद execute करता।
उदाहरण: Seeing the Output in Code
// Entry point: execution of the program starts here
fn main() {
// Print "Built with cargo build, or run directly with cargo run" to the console (with a trailing newline)
println!("Built with cargo build, or run directly with cargo run");
}
Login to try C/C++/Java/PHP code in the editor
- quick iteration के लिए सीधे
cargo runउपयोग करने के बजायcargo buildचलाना और फिर हाथ से binary ढूंढना। - यह न समझना कि
cargo build --releaseएक कहीं ज़्यादा तेज़, optimized binary produce करता है, और इसके बजाय debug build के साथ benchmarking करना। target/folder को यह सोचकर delete करना कि इसमें source code है, जबकि यह safe-to-delete build output है।
cargo buildproject compile करता है और executable कोtarget/debug/के नीचे रखता है।cargo runcompile करता है (अगर ज़रूरत हो) और एक ही step में तुरंत resulting binary चलाता है।cargo build --releaseएक optimized binary produce करता हैtarget/release/के नीचे, जो production/performance के लिए उपयोग होता है।- Cargo सिर्फ बदली हुई files को फिर से compile करता है, जो repeated builds को तेज़ बनाता है।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: