Cargo installation
Variables learning
Data Types
Ownership
memory & allocation
code

here as per normal case you will think that this s2 string will be get copied to s1 string.
in rust s1 value will get copied to s2 but s1 value will get removed.
so in short if you simply assign s1 = “hello”; s2 = s1 . they value of s2 will be “hello” but value of s1 will get removed. basically value of s1 is moved to s2.
if we try to print y value will get compile time error.
and if you want to specifically clone/copy value from x to y by keeping y then you can use s1.clone()
but in above code case x will be copy to y. in rust i will use as special copy tray for variables like int, bool and char.
Takes_ownership
code
fn main() {
let s = String::from("hello");
takes_owership(s);
println!("{}",s);
}
fn takes_owership(some_string:String){
println!("{}",some_string);
}
this will give error. why bcz takes_ownership func takes ownership of that string. so as per above memory & allocation logic it will give error.
as strings s value is moved to the func some_string.
if we use same logic for int , bool , char then as per we know this will copy the values and will get value printed.
Gives_ownership
code
xfn main() {
let s = gives_owership();
println!("{}",s);
}
fn gives_owership() -> String {
let some_string = String::from("hello");
some_string
}
this code will work fine and give you the hello o/p as expected. as give ownership func gives ownership and returns some_string which will print in main.
Takes_and_gives back
code
fn main() {
let s1 = gives_owership();
let s2 = String::from("hello");
let s3 = takes_and_gives_back(s2);
println!("s1:{},s3:{}",s1,s3);
}
fn gives_owership() -> String {
let some_string = String::from("hello");
some_string
}
fn takes_and_gives_back(a_string: String) -> String{
a_string
}
Referencing
Slices
Structs
Enums and pattern matching
code

we can create enum like this. but we can also create separate struct like below :

but if we do like this we will not have same type structs with enum we can group them in same message type.
The Option Enum :
but rust dont have null values so we use options.
for doing sum or any math we cant directly add or do math on int x and option int y.
we can use unwrap for this.

Match Expression
both above are same but if else is some what confusing. it starts with “if let” then if some_value = some(3) then it will print “three”. some what diff.

RUST module explained
Common Collections in Rust
Error Handling
Generic Types In RUST
Traits
RUST Lifetimes
Testing in RUST