Agenda Why learn Rust? What is Rust? Rust Fundamentals 01 02 03 RUST
Why learn Rust?
Why Rust? Cargo packet managerConcurrency Memory safety Zero cost abstraction
Rust Stats
What is Rust? Zero cost abstraction Efficient C binding Ensures memory safety Pattern matching Error messages Threads without data races Rust is a safe, concurrent, systems programming language developed by a Mozilla employee, Graydon Hoare in 2006.
Install Rust On Linux
Rust Fundamentals
Variables Memory location Variable name Variable is a name given to a memory location which acts as a container for storing data. Syntax: 1 let mut age=15; 2 age=16;
Constants Constants are fixed values that do not change during execution time. Syntax: 1 2 const x: f32 = 1.54; Examples of constants
Scalar Data Types Character Boolean TRUE FALSE Integer Floating-point 12.34 y
Compound Data Types - Arrays An array is a data structure that contains a list of elements. These elements are all of the same data type, such as an integer or string. Syntax: 1 2 let arr=[ ]; 0 1 2 3 4 5 6
Compound Data Types - Tuple A tuple is a data structure that contains a list of elements. These elements can be of different data type, such as an integer or string. Syntax: 1 2 let tup: (i32, f64, u8) = (200, 1.2, 2); 0 1 2 3 4
Strings A string is basically an array of characters. Syntax: 1 2 let mut s = String::new( ); E D U R E K A 0 1 2 3 4 5 6
Functions A function is a block of organized, reusable code that is used to perform a single, related action. Functions Predefined Functions User Defined Functions Syntax: 1 2 3 fn greetings( ) { println!(“Hello everyone!”); } name of the function enter parameters here
Conditional Statements - If Conditional statement is a set of rules performed if a certain condition is met. It is like an ‘If-Then’ statement. (IF a condition is met, THEN an action is performed) If code End Start True Condition False Exit Syntax: 1 2 3 if(condition) { statement; }
Conditional Statements – If else Conditional statement is a set of rules performed if a certain condition is met. It is like an ‘If-Then’ statement. (IF a condition is met, THEN an action is performed) If code End Start True Condition False Else if code Syntax: 1 2 3 4 5 6 if(condition) { statement a; } else { statement b; }
Conditional Statements – Else if Conditional statement is a set of rules performed if a certain condition is met. It is like an ‘If-Then’ statement. (IF a condition is met, THEN an action is performed) If code End Start True Condition False Else if code Syntax: 1 2 3 4 5 6 7 8 9 if(condition) { statement a; } else if(condition) { statement b; } else { statement c; }
Loop Loop is used to repeat a specific block until some end condition is met. Start Conditional Code Condition False True End loop Syntax: 1 2 3 loop { statements; }
For Loop Repeatedly executes the loop code while a given condition is TRUE. It tests the condition before executing the loop body. Start Execute Statement (s) End Next item from sequence If no more itemsItem from sequenceSyntax: 1 2 3 4 for var in expression { block statements; }
While Loop While the condition is true, the code within the loop is executed. Start Conditional Code End True False Condition Syntax: 1 2 3 while(condition) { loop code; }
Ownership When a block of code owns a resource, it is known as ownership. • Every value has a variable associated which is the owner • There can only be one owner at a time • If the owner goes out of scope, the value associated with it is destroyed RULES Example: 1 2 let x=12; let y=x;
Structure A structure is a user-defined data type that consists of variables of different data types. Syntax: 1 2 3 4 5 struct Student { variable: data-type; variable: data-type; } Name Age Father’s name
Enum Enum is a custom data type which contains some definite values. Syntax: 1 2 3 4 5 enum enum_name { variant1, variant2, } Stop Ready Go Traffic Signal
Modules A module is a namespace which contains the definitions of the functions or its types. A module is a collection of items such as functions, traits, structs, blocks. Syntax: 1 2 3 mod module_name { module body } • mod - declares the new module • pub - makes the visibility modifier as public & accessible outside the namespace • use - to import the module into local scope Keywords used in modules:
Vectors Vectors allow you to store more than one value in a single data structure that puts all the values next to each other in memory. Syntax: 1 2 let v : Vec<i32> = Vec::new( ); • Stores values of the same data type • It is denoted by Vec<T> • It is a growable array Key points of Vectors:
Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Training | Edureka

Rust Tutorial | Rust Programming Language Tutorial For Beginners | Rust Training | Edureka

  • 2.
    Agenda Why learn Rust?What is Rust? Rust Fundamentals 01 02 03 RUST
  • 3.
  • 4.
    Why Rust? Cargo packetmanagerConcurrency Memory safety Zero cost abstraction
  • 5.
  • 6.
    What is Rust? Zerocost abstraction Efficient C binding Ensures memory safety Pattern matching Error messages Threads without data races Rust is a safe, concurrent, systems programming language developed by a Mozilla employee, Graydon Hoare in 2006.
  • 7.
  • 8.
  • 9.
    Variables Memory location Variable name Variableis a name given to a memory location which acts as a container for storing data. Syntax: 1 let mut age=15; 2 age=16;
  • 10.
    Constants Constants are fixedvalues that do not change during execution time. Syntax: 1 2 const x: f32 = 1.54; Examples of constants
  • 11.
  • 12.
    Compound Data Types- Arrays An array is a data structure that contains a list of elements. These elements are all of the same data type, such as an integer or string. Syntax: 1 2 let arr=[ ]; 0 1 2 3 4 5 6
  • 13.
    Compound Data Types- Tuple A tuple is a data structure that contains a list of elements. These elements can be of different data type, such as an integer or string. Syntax: 1 2 let tup: (i32, f64, u8) = (200, 1.2, 2); 0 1 2 3 4
  • 14.
    Strings A string isbasically an array of characters. Syntax: 1 2 let mut s = String::new( ); E D U R E K A 0 1 2 3 4 5 6
  • 15.
    Functions A function isa block of organized, reusable code that is used to perform a single, related action. Functions Predefined Functions User Defined Functions Syntax: 1 2 3 fn greetings( ) { println!(“Hello everyone!”); } name of the function enter parameters here
  • 16.
    Conditional Statements -If Conditional statement is a set of rules performed if a certain condition is met. It is like an ‘If-Then’ statement. (IF a condition is met, THEN an action is performed) If code End Start True Condition False Exit Syntax: 1 2 3 if(condition) { statement; }
  • 17.
    Conditional Statements –If else Conditional statement is a set of rules performed if a certain condition is met. It is like an ‘If-Then’ statement. (IF a condition is met, THEN an action is performed) If code End Start True Condition False Else if code Syntax: 1 2 3 4 5 6 if(condition) { statement a; } else { statement b; }
  • 18.
    Conditional Statements –Else if Conditional statement is a set of rules performed if a certain condition is met. It is like an ‘If-Then’ statement. (IF a condition is met, THEN an action is performed) If code End Start True Condition False Else if code Syntax: 1 2 3 4 5 6 7 8 9 if(condition) { statement a; } else if(condition) { statement b; } else { statement c; }
  • 19.
    Loop Loop is usedto repeat a specific block until some end condition is met. Start Conditional Code Condition False True End loop Syntax: 1 2 3 loop { statements; }
  • 20.
    For Loop Repeatedly executesthe loop code while a given condition is TRUE. It tests the condition before executing the loop body. Start Execute Statement (s) End Next item from sequence If no more itemsItem from sequenceSyntax: 1 2 3 4 for var in expression { block statements; }
  • 21.
    While Loop While thecondition is true, the code within the loop is executed. Start Conditional Code End True False Condition Syntax: 1 2 3 while(condition) { loop code; }
  • 22.
    Ownership When a blockof code owns a resource, it is known as ownership. • Every value has a variable associated which is the owner • There can only be one owner at a time • If the owner goes out of scope, the value associated with it is destroyed RULES Example: 1 2 let x=12; let y=x;
  • 23.
    Structure A structure isa user-defined data type that consists of variables of different data types. Syntax: 1 2 3 4 5 struct Student { variable: data-type; variable: data-type; } Name Age Father’s name
  • 24.
    Enum Enum is acustom data type which contains some definite values. Syntax: 1 2 3 4 5 enum enum_name { variant1, variant2, } Stop Ready Go Traffic Signal
  • 25.
    Modules A module isa namespace which contains the definitions of the functions or its types. A module is a collection of items such as functions, traits, structs, blocks. Syntax: 1 2 3 mod module_name { module body } • mod - declares the new module • pub - makes the visibility modifier as public & accessible outside the namespace • use - to import the module into local scope Keywords used in modules:
  • 26.
    Vectors Vectors allow youto store more than one value in a single data structure that puts all the values next to each other in memory. Syntax: 1 2 let v : Vec<i32> = Vec::new( ); • Stores values of the same data type • It is denoted by Vec<T> • It is a growable array Key points of Vectors: