From abb4218b558cadf95337cea70c1a46397b631389 Mon Sep 17 00:00:00 2001 From: Ramaguru Radhakrishnan <7790256+ramagururadhakrishnan@users.noreply.github.com> Date: Tue, 7 May 2024 20:59:32 +0530 Subject: [PATCH] Updated - Descriptions - Comments to the Code --- Assets/Lectures/RL1.md | 50 ++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/Assets/Lectures/RL1.md b/Assets/Lectures/RL1.md index 3224cd8..f1e40c9 100644 --- a/Assets/Lectures/RL1.md +++ b/Assets/Lectures/RL1.md @@ -5,31 +5,57 @@ ## Lecture 1 - Introducton to Rust Programming ![](https://img.shields.io/badge/-1st_Apr-orange) +**Rust is:** +- fast and memory-efficient +- no runtime or garbage collector +- rich type system +- ownership model guarantee +- system programming language +- immutability and higher-order functions ### Hello World Program ``` -fn main() { - println!("Hello, world!"); +fn main() { // 'main' function is the entry point to the program + + println!("Hello, world!"); // Macro call to println. ! denotes a macro + } ``` +```fn``` keyword denotes a function, and the ```println!``` macro prints the message to standard output. +Statements in Rust are separated by semicolons. + +#### Compile +``` +rustc <>.rs +``` + +### Mutable Variables -### Example 1 ``` -use std::io; +// guessingNumber.rs -fn main() { - println!("Guess the number!"); // Macro call +use std::io; // use io module from standard library - println!("Please input your guess."); +fn main() { // 'main' function is the entry point to the program - let mut guess = String::new(); // Mutable Var. + println!("Guess the number!"); // Macro call to println - io::stdin() // instance - .read_line(&mut guess) // Ok / Err - .expect("Failed to read line"); + println!("Please input your guess."); // Macro call to println - println!("You guessed: {guess}"); + let mut guess = String::new(); // Mutable Variable. + + io::stdin() // returns the instance of 'std::io::Stdin' + .read_line(&mut guess) // read the input from the console and append it to guess - Ok / Err + .expect("Failed to read line"); // terminates the program on any error + + println!("You guessed: {guess}"); // Macro call to println } ``` + +To Compile and Run: +``` +> rustc guessingNumber.rs +> guessingNumber.exe +```