Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some more examples. Uncommented some codes. #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,61 @@ fn main() {
// float is used for decimals
let float = 0.32;

// println!("Different numbers => {}, {}, {}", unsigned, signed, float);
println!("Different numbers => {}, {}, {}", unsigned, signed, float);

// char is used for single character
let character = 'a';
// println!("Character => {}", character);
println!("Character => {}", character);

// boolean is used for true or false
let boolean = true;
// println!("Boolean => {}", boolean);
println!("Boolean => {}", boolean);

// tuple is used for grouping different data types
let tuple = (1, -2, 3.0, 4, true);
// println!("Tuple => {:?}", tuple);
println!("Tuple => {:?}", tuple);

// array is used for grouping same data types
let array = [1, 2, 3, 4, 5];
// println!("Array => {:?}", array);
println!("Array => {:?}", array);

// string is used for grouping characters
let string = "Hello World";
// println!("String => {}", string);
println!("String => {}", string);

// vector is used for grouping same data types and it is dynamic
let mut vector = vec![1, 2, 3, 4, 5];
vector.push(6);
// println!("Vector => {:?}", vector);
println!("Vector => {:?}", vector);

// hash map is used for grouping 2 different data types as key value pair
let mut hash_map = std::collections::HashMap::new();
hash_map.insert("Solana", 100);
hash_map.insert("age", 2);
// println!("Hash Map => {:?}", hash_map);
println!("Hash Map => {:?}", hash_map);

// enums

#[derive(Debug)]
enum Color {
Red,
Green,
Blue,
}
let mut enum_color :Color = Color::Red;
println!("When the color is Red the value is {:?}",enum_color);
enum_color = Color::Blue;
println!("Now the color is {:?}",enum_color);

// hash set is used for grouping same data types

let mut hash_set = std::collections::HashSet::new();

hash_set.insert("John Doe");
hash_set.insert("Jane Doe");
hash_set.insert("Jane Doe");
// Should only display two entries

// println!("Hash Set => {:?}", hash_set);
println!("Hash Set => {:?}", hash_set);

// Looping

Expand Down Expand Up @@ -93,4 +99,9 @@ fn main() {
for (index, value) in array.iter().enumerate() {
println!("Value at index {}: {}", index, value);
}

// Loop over key and values of the HashMap
for (k,v) in hash_map.iter() {
println!("HashMap key : {}, value : {}",k,v);
}
}