├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── readme.md └── src └── main.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "hello_calyptus" 7 | version = "0.1.0" 8 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello_calyptus" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Introduction To Rust 2 | 3 | Based on the [Introduction to Rust Programming](httpshttps://calyptus.co/lessons/introduction-to-rust-programming/) lesson, this walkthrough quickly gets you up to speed on how you can get started building fearlessly using Rust on Solana. 4 | 5 | ## Table of Contents 6 | - [Getting Started](#getting-started) 7 | - [Contributing](#contributing) 8 | - [Questions](#questions) 9 | - [License](#license) 10 | 11 | ## Getting Started 12 | 13 | To use this fork, you need to have [Rust](https://www.rust-lang.org/tools/install) installed on your machine. 14 | 15 | To use the fork, follow the steps outlined below: 16 | 17 | 1. Clone your forked repo. 18 | 19 | ```bash 20 | git clone https://github.com//anchor-todo-list 21 | ``` 22 | 23 | ## Contributing 24 | 25 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 26 | 27 | ## Questions 28 | 29 | Did you encounter a challenge following the tutorial or running the fork? 30 | Head over to our [learning support](https://discord.com/channels/1130457754826461216/1132978998155165806) channel on our [Discord](https://discord.gg/38KftAhW) or alternatively, raise a ticket. 31 | 32 | We are always happy to lend a helping hand 33 | 34 | ## License 35 | 36 | All files within this repository are licensed under the MIT License unless explicitly stated otherwise. 37 | 38 | 100% Open Source software. 39 | 40 | © 2023 [Calyptus] - See [LICENSE](https://opensource.org/license/mit/) for details. -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // unsigned integer 3 | // u8, u16, u32, u64, u128 4 | let unsigned: u32 = 10; 5 | 6 | // signed integer 7 | // i8, i16, i32, i64, i128 8 | let signed = -10; 9 | 10 | // float is used for decimals 11 | let float = 0.32; 12 | 13 | // println!("Different numbers => {}, {}, {}", unsigned, signed, float); 14 | 15 | // char is used for single character 16 | let character = 'a'; 17 | // println!("Character => {}", character); 18 | 19 | // boolean is used for true or false 20 | let boolean = true; 21 | // println!("Boolean => {}", boolean); 22 | 23 | // tuple is used for grouping different data types 24 | let tuple = (1, -2, 3.0, 4, true); 25 | // println!("Tuple => {:?}", tuple); 26 | 27 | // array is used for grouping same data types 28 | let array = [1, 2, 3, 4, 5]; 29 | // println!("Array => {:?}", array); 30 | 31 | // string is used for grouping characters 32 | let string = "Hello World"; 33 | // println!("String => {}", string); 34 | 35 | // vector is used for grouping same data types and it is dynamic 36 | let mut vector = vec![1, 2, 3, 4, 5]; 37 | vector.push(6); 38 | // println!("Vector => {:?}", vector); 39 | 40 | // hash map is used for grouping 2 different data types as key value pair 41 | let mut hash_map = std::collections::HashMap::new(); 42 | hash_map.insert("Solana", 100); 43 | hash_map.insert("age", 2); 44 | // println!("Hash Map => {:?}", hash_map); 45 | 46 | // enums 47 | 48 | enum Color { 49 | Red, 50 | Green, 51 | Blue, 52 | } 53 | 54 | // hash set is used for grouping same data types 55 | 56 | let mut hash_set = std::collections::HashSet::new(); 57 | 58 | hash_set.insert("John Doe"); 59 | hash_set.insert("Jane Doe"); 60 | 61 | // println!("Hash Set => {:?}", hash_set); 62 | 63 | // Looping 64 | 65 | for i in 0..10 { 66 | println!("Looping => {}", i); 67 | } 68 | 69 | let mut i = 0; 70 | while i < 10 { 71 | println!("Looping => {}", i); 72 | i += 1; 73 | } 74 | 75 | let mut counter = 0; 76 | loop { 77 | println!("Looping..."); 78 | 79 | counter += 1; 80 | if counter >= 5 { 81 | break; 82 | } 83 | } 84 | 85 | // Looping over an array 86 | let array = [10, 20, 30, 40, 50]; 87 | for element in array.iter() { 88 | println!("Array element: {}", element); 89 | } 90 | 91 | // Looping over an iterator 92 | let array = [100, 200, 300, 400, 500]; 93 | for (index, value) in array.iter().enumerate() { 94 | println!("Value at index {}: {}", index, value); 95 | } 96 | 97 | // Implementation 98 | 99 | // Define a struct 100 | struct Rectangle { 101 | width: u32, 102 | height: u32 103 | } 104 | 105 | // Add a method to the struct via impl keyword 106 | impl Rectangle { 107 | fn area(&self) -> u32 { 108 | self.width * self.height 109 | } 110 | } 111 | 112 | let rect = Rectangle { width: 30, height: 50 }; 113 | println!("The area of the rectangle is {}", rect.area()); 114 | 115 | // Implementation using trait 116 | trait HasArea { 117 | fn area(&self) -> f64; 118 | } 119 | 120 | struct Square { 121 | side: f64 122 | } 123 | 124 | impl HasArea for Square { 125 | fn area(&self) -> f64 { 126 | self.side * self.side 127 | } 128 | } 129 | 130 | let area_calc = Square {side: 2.0}; 131 | println!("Calculation for the area of the rectangle using a trait is {}", area_calc.area()); 132 | } 133 | --------------------------------------------------------------------------------