Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
- Descriptions
- Comments to the Code
  • Loading branch information
ramagururadhakrishnan committed May 7, 2024
1 parent c6101c9 commit abb4218
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions Assets/Lectures/RL1.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<filename>>.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
```

0 comments on commit abb4218

Please sign in to comment.