fn main() {
println!("Hello World!");
}
Details
println!("{}", 1);
println!("{} {}", 1, 3);
println!("{0} is {1} {2}, also {0} is a {3} programming language", "Rust", "cool", "language", "safe");
println!("{country} is a diverse nation with unity.", country = "India");
println!("Let us print 76 is binary which is {:b} , and hex equivalent is {:0x} and octal equivalent is {:o}", 76, 76, 76);
println!("Print whatever we want to here using debug trait {:?}", (76, 'A', 90));
let x = "world";
println!("Hello {x}!");
- Signed integers:
i8
, i16
, i32
, i64
, i128
and isize
- Unsigned integers:
u8
, u16
, u32
, u64
, u128
and usize
- Floating point:
f32
, f64
char
: Unicode scalar values (4 bytes each)bool
- unit type
()
, whose only possible value is empty ()
- Arrays like
[1, 2, 3]
- Tuples like
(1, true)
let mut array: [ i64; 4] = [1,2,3,4];
let mut slices: &[i64] = &array[0..3]
println!("The elements of the slices are : {slices:?}");
let cs:&str = "cheat sheet";
let my_string = String::new();
let S_string = a_string.to_string()
let lang = String::from("Rust");
let name = String::from("ElementalX");
name.contains("Element")
let mut half_text = String::from("Hal");
half_text.push('f');
let mut hi = String::from("Hey there...");
hi.push_str("How are you doing??");
println!("{hi}");
let foo = 12;
let bar = 13;
if foo == bar {
println!("foo is equal to bar");
} else if foo < bar {
println!("foo less than bar");
} else if foo != bar {
println!("foo is not equal to bar");
} else {
println!("Nothing");
}
let mut arr1:[i64 ; 3] = [1,2,3];
if let[1,2,_] = arr1{
println!("Works with array");
}
let mut arr2:[&str; 2] = ["one", "two"];
if let["Apple", _] = arr2{
println!("Works with str array too");
}
let day_of_week = 2;
match day_of_week {
1 => {
println!("Its Monday my dudes");
},
2 => {
println!("It's Tuesday my dudes");
},
_ => {
println!("Default!")
}
};
let mut i = 1;
loop {
println!("i is {i}");
if i > 100 {
break;
}
if i > 50 {
continue;
}
i *= 2;
}
for mut i in 0..15 {
println!("The value of i is : {i}");
}
let mut check = 0;
while check < 11{
println!("Check is : {check}");
check+=1;
println!("After incrementing: {check}");
if check == 10{
break;
}
}