Rust परिचय
What is Rust?
Rust एक open-source, statically typed, compiled systems programming language है जिसे Mozilla ने बनाया और पहली बार 2010 में release किया।
यह C और C++ जैसी languages की speed और control देने के लिए design की गई है, साथ ही runtime के बजाय compile time पर memory safety की गारंटी देने के लिए एक unique ownership system उपयोग करते हुए।
उदाहरण: What is Rust?
// Entry point: execution of the program starts here
fn main() {
// Print "Rust is a systems programming language" to the console (with a trailing newline)
println!("Rust is a systems programming language");
// Print "It is fast, safe, and compiled" to the console (with a trailing newline)
println!("It is fast, safe, and compiled");
}
Login to try C/C++/Java/PHP code in the editor
Why Rust Was Created
Rust को memory-safety bugs (जैसे null pointer dereferences और data races) solve करने के लिए design किया गया जो C और C++ programs को परेशान करते हैं, बिना एक garbage collector की performance cost चुकाए।
इसका ownership model compile time पर memory usage rules जांचता है, इसलिए bugs की एक पूरी category एक successfully compile होने वाले program में बिल्कुल मौजूद नहीं हो सकती।
उदाहरण: Why Rust Was Created
// Entry point: execution of the program starts here
fn main() {
// Declare an immutable variable `goals`, set to `["memory safety", "zero-cost abstractions", "fearless concurrency"]`
let goals = ["memory safety", "zero-cost abstractions", "fearless concurrency"];
// Loop over `goals.iter()`, binding each item to `g`
for g in goals.iter() {
// Print "Design goal: {}" to the console, substituting in `g` (with a trailing newline)
println!("Design goal: {}", g);
}
}
Login to try C/C++/Java/PHP code in the editor
Where Rust Is Used
Rust command-line tools, web backends, operating system components, browser engines, और game engines के लिए उपयोग होता है इसकी speed और safety guarantees के कारण।
Mozilla, Microsoft, Amazon, और Discord जैसी companies performance-critical services के लिए Rust उपयोग करती हैं जहां crashes या memory bugs स्वीकार्य नहीं हैं।
उदाहरण: Where Rust Is Used
// Entry point: execution of the program starts here
fn main() {
// Declare an immutable variable `used_for`, set to `[("Firefox", "browser engine parts"), ("AWS", "infrastructure tools"), ("Discord", "backend services")]`
let used_for = [("Firefox", "browser engine parts"), ("AWS", "infrastructure tools"), ("Discord", "backend services")];
// Loop over `used_for.iter()`, binding each item to `(company, purpose)`
for (company, purpose) in used_for.iter() {
// Print "{}: {}" to the console, substituting in `company, purpose` (with a trailing newline)
println!("{}: {}", company, purpose);
}
}
Login to try C/C++/Java/PHP code in the editor
Compiled, Not Interpreted
Python या JavaScript के विपरीत, Rust source code चलने से पहले rustc द्वारा एक native executable में ahead of time compile किया जाता है।
इसका मतलब है compiler types, ownership, और कई logic errors को program शुरू होने से पहले जांच लेता है, और resulting binary बिना उस machine पर Rust installed हुए चलती है जो इसे execute करती है।
rustc main.rs एक executable file produce करता है जिसे आप सीधे चला सकते हैं।उदाहरण: Compiled, Not Interpreted
// Entry point: execution of the program starts here
fn main() {
// Print "This program was compiled to machine code before running" to the console (with a trailing newline)
println!("This program was compiled to machine code before running");
// Print "No interpreter is needed at runtime" to the console (with a trailing newline)
println!("No interpreter is needed at runtime");
}
Login to try C/C++/Java/PHP code in the editor
- यह मान लेना कि Rust सिर्फ systems programming experts के लिए है और इसे skip कर देना क्योंकि यह beginners के लिए बहुत कठिन लगती है।
- Rust की compiler errors को failures के साथ confuse करना -- compiler असल में program कभी चलने से पहले bugs पकड़ रहा है।
- यह सोचना कि Rust को Java या Python जैसे garbage collector की ज़रूरत है; यह इसके बजाय ownership rules के ज़रिए memory manage करती है।
- Rust एक systems programming language है जो speed, memory safety, और safe concurrency पर केंद्रित है।
- यह अपने ownership और borrowing system के ज़रिए बिना किसी garbage collector के memory safety हासिल करती है।
- Rust तेज़ native binaries में compile होती है और CLI tools, web backends, game engines, और embedded systems के लिए उपयोग होती है।
- इसका सख्त compiler runtime के बजाय compile time पर कई bugs पकड़ता है।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: