Posts

Showing posts from January, 2024

Rust - Compound Types

 Compound Types: Tuple let info = (1,3.3.999); info.0; --> let(x,y,z) = info; will initialize x to 1, y to 3.3 and z to 999. Array: support size of 32 only. let buf = [1,2,3]; buf[0],buf[1],buf[2].

Rust - Scalar Types

  Integers: Unsigned   Signed u8 - i8 u16 - i16 u32 - i32 u64 - i64 u128 - i128 usize - isize -- equal to platform size float:  f32 f64 let x = 5_u16;   and  let x = 5u16; and let x:u16 = 5; are same. let y = 3.14_f32   and  let y = 3.14f32 and let y:f32 = 3.14; are same; boolean true,false char is not 8byte. Any action sound to emoj and character. Useless..

Rust - Module System

 libraries are called Module System in Rust. lib.rs --> pub fn greet(){println!();} greet is called as lib::greet(); or  use lib::greet; fn main(){      greet();      }

Rust - Functions

 Functions: fn keyword used to define a function fn main(){ } fn do_stuff(a:i23, b:i32) -> i32 { return a+b; } fn do_stuff(a:i23, b:i32) -> i32 {           a+b  // this will return automatically } variable number of arguments won't support in rust but macros support variable number of arguments  println! is macro.

Rust - Memory Safety

 Memory Safety Rust guarantees memory safety at compile time. Unlike C , uninitialized variables are not allowed. Rust will give a compile error for uninitialised variables.

Rust - Scope

 Scope: scope of a variable starts where it's defined and ends at the bloc's end. always local to scope fn main(){ let x = 5; {     let x = 6;     println!({},x);//x value 6 } println!("{}",x); //x value is 5 }

Rust - Threads

 Threads

Rust - Closures

 Closures

Rust - Enums

 Enums

Rust - Collections

 Collections

Rust - Traits

 Traits

Rust - Structs

 Structs

Rst - References & Borrowing

 References & Borrowing

Rust - Primitive Types And Control Flow

 Scalar Types Compound Types Control Flow Strings

Rust - Variables

Variables To declare a variable we can simply use as below: let var  = 2; to define the variable type let var:i32  = 2; the variable var will be defined as i32 type. for multiple variables let (var1, var2) = (8,30); -- tple patrens Variable are immutables by default unless we specify as a table like, the above variable var can not be changed by default. let mut var  = 2; with default immutables Safety,  Concurrency, and Speed will be increased with optimization. const PI_VALUE: f64 = 3.14;

What is Rust Programming Language