← Back to Rust Course | Chapter 1: Setup & Basics | Lesson 1 of 7

Rust परिचय

Rust एक programming language है जो computers को programs बहुत तेज़ी से चलाने में मदद करती है, साथ ही आपको उन गलतियों से रोकती है जो crashes का कारण बनती हैं।

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?

markup
// 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");
}

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 में बिल्कुल मौजूद नहीं हो सकती।

Note: "Fearless concurrency" Rust community से एक phrase है जिसका मतलब है कि compiler code चलाने से पहले ही data races रोक देता है।

उदाहरण: Why Rust Was Created

markup
// 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);
    }
}

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

markup
// 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);
    }
}

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 करती है।

Note: आप compiled binary खुद देख सकते हैं: rustc main.rs एक executable file produce करता है जिसे आप सीधे चला सकते हैं।

उदाहरण: Compiled, Not Interpreted

markup
// 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");
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह मान लेना कि Rust सिर्फ systems programming experts के लिए है और इसे skip कर देना क्योंकि यह beginners के लिए बहुत कठिन लगती है।
  2. Rust की compiler errors को failures के साथ confuse करना -- compiler असल में program कभी चलने से पहले bugs पकड़ रहा है।
  3. यह सोचना कि 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:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.