├── .DS_Store ├── rustlabs101 ├── basic-formatting │ ├── single-placeholder.rs │ ├── multiple-placeholders.rs │ ├── debug-trailt.rs │ ├── placeholder-traits.rs │ ├── positional-arguments.rs │ └── named-arguments.rs ├── loop │ ├── loop │ ├── while │ ├── for-loop │ ├── enumerate │ ├── loop-label │ ├── nested-loop │ ├── continue-loop │ ├── break-stat-loop │ ├── break-stat-while │ ├── continue-while │ ├── continue-for-loop │ ├── break-stat-for-loop │ ├── for-loop.rs │ ├── enumerate.rs │ ├── break-stat-for-loop.rs │ ├── loop.rs │ ├── break-stat-loop.rs │ ├── nested-loop.rs │ ├── break-stat-while.rs │ ├── continue-for-loop.rs │ ├── continue-loop.rs │ ├── loop-label.rs │ ├── while.rs │ └── continue-while.rs ├── Strings │ ├── Concatenat │ ├── String-obj │ ├── fn-string-obj │ ├── format-micro │ ├── push-string │ ├── String-Capcity │ ├── String-literal │ ├── find-substring │ ├── slicing-string │ ├── fn-string-literal │ ├── push-single-char │ ├── replace-substring │ ├── slicing-string.rs │ ├── push-string.rs │ ├── push-single-char.rs │ ├── trim-string.rs │ ├── String-Capcity.rs │ ├── fn-string-obj.rs │ ├── fn-string-literal.rs │ ├── String-literal.rs │ ├── Concatenat.rs │ ├── find-substring.rs │ ├── replace-substring.rs │ ├── format-micro.rs │ └── String-obj.rs ├── hello-world │ ├── hello-world.rs │ └── hello-world ├── printing-styles │ ├── eprint.rs │ ├── eprintln │ ├── println.rs │ └── eprintln.rs ├── structs │ ├── fn-struct │ ├── define-struct │ ├── method-struct │ ├── return-struct │ ├── fn-struct.rs │ ├── method-struct.rs │ ├── define-struct.rs │ └── return-struct.rs ├── data-type │ ├── get-slice │ ├── len-array │ ├── mut-array │ ├── mut-tuple │ ├── print-array │ ├── print-tuple │ ├── bool-explicit │ ├── bool-implicit │ ├── char-explicit │ ├── char-implicit │ ├── define-array │ ├── define-tuple │ ├── int-explicit │ ├── int-implicit │ ├── float-explicit │ ├── float-implicit │ ├── char-explicit.rs │ ├── string-implicit.rs │ ├── bool-explicit.rs │ ├── string-explicit.rs │ ├── bool-implicit.rs │ ├── float-implicit.rs │ ├── len-array.rs │ ├── float-explicit.rs │ ├── char-implicit.rs │ ├── print-tuple.rs │ ├── print-array.rs │ ├── mut-array.rs │ ├── int-implicit.rs │ ├── int-explicit.rs │ ├── get-slice.rs │ ├── define-array.rs │ ├── mut-tuple.rs │ └── define-tuple.rs ├── functions │ ├── define-fn │ ├── multi-return │ ├── pass-by-value │ ├── return-array │ ├── function-param │ ├── returning-value │ ├── fn-array-pass-ref │ ├── fn-array-pass-val │ ├── pass-by-reference │ ├── define-fn.rs │ ├── fn-array-pass-ref.rs │ ├── return-array.rs │ ├── pass-by-value.rs │ ├── pass-by-reference.rs │ ├── function-param.rs │ ├── multi-return.rs │ ├── fn-array-pass-val.rs │ └── returning-value.rs ├── operators │ ├── bitwise-op │ ├── logical-op │ ├── arithmetic-op │ ├── borrowing-op │ ├── comparison-op │ ├── dereferencing-op │ ├── type-casting-op │ ├── assignment-compound-op │ ├── type-casting-op.rs │ ├── logical-op.rs │ ├── arithmetic-op.rs │ ├── comparison-op.rs │ ├── bitwise-op.rs │ ├── dereferencing-op.rs │ ├── assignment-compound-op.rs │ └── borrowing-op.rs ├── scope-shadowing │ ├── scope │ ├── shadowing │ ├── shadowing.rs │ └── scope.rs └── variable │ ├── mut-variable │ ├── init-variable │ ├── multi-variable │ ├── init-variable.rs │ ├── multi-variable.rs │ └── mut-variable.rs └── readme.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/.DS_Store -------------------------------------------------------------------------------- /rustlabs101/basic-formatting/single-placeholder.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("Number: {}", 1); 3 | } -------------------------------------------------------------------------------- /rustlabs101/loop/loop: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/loop/loop -------------------------------------------------------------------------------- /rustlabs101/loop/while: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/loop/while -------------------------------------------------------------------------------- /rustlabs101/loop/for-loop: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/loop/for-loop -------------------------------------------------------------------------------- /rustlabs101/loop/enumerate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/loop/enumerate -------------------------------------------------------------------------------- /rustlabs101/loop/loop-label: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/loop/loop-label -------------------------------------------------------------------------------- /rustlabs101/loop/nested-loop: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/loop/nested-loop -------------------------------------------------------------------------------- /rustlabs101/Strings/Concatenat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/Strings/Concatenat -------------------------------------------------------------------------------- /rustlabs101/Strings/String-obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/Strings/String-obj -------------------------------------------------------------------------------- /rustlabs101/hello-world/hello-world.rs: -------------------------------------------------------------------------------- 1 | //hello world program 2 | fn main() { 3 | println!("Hello World!"); 4 | } 5 | -------------------------------------------------------------------------------- /rustlabs101/loop/continue-loop: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/loop/continue-loop -------------------------------------------------------------------------------- /rustlabs101/printing-styles/eprint.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | eprint!("Rust Programming"); 3 | eprint!("Rustlabs"); 4 | } -------------------------------------------------------------------------------- /rustlabs101/structs/fn-struct: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/structs/fn-struct -------------------------------------------------------------------------------- /rustlabs101/Strings/fn-string-obj: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/Strings/fn-string-obj -------------------------------------------------------------------------------- /rustlabs101/Strings/format-micro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/Strings/format-micro -------------------------------------------------------------------------------- /rustlabs101/Strings/push-string: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/Strings/push-string -------------------------------------------------------------------------------- /rustlabs101/data-type/get-slice: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/data-type/get-slice -------------------------------------------------------------------------------- /rustlabs101/data-type/len-array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/data-type/len-array -------------------------------------------------------------------------------- /rustlabs101/data-type/mut-array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/data-type/mut-array -------------------------------------------------------------------------------- /rustlabs101/data-type/mut-tuple: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/data-type/mut-tuple -------------------------------------------------------------------------------- /rustlabs101/data-type/print-array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/data-type/print-array -------------------------------------------------------------------------------- /rustlabs101/data-type/print-tuple: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/data-type/print-tuple -------------------------------------------------------------------------------- /rustlabs101/functions/define-fn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/functions/define-fn -------------------------------------------------------------------------------- /rustlabs101/loop/break-stat-loop: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/loop/break-stat-loop -------------------------------------------------------------------------------- /rustlabs101/loop/break-stat-while: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/loop/break-stat-while -------------------------------------------------------------------------------- /rustlabs101/loop/continue-while: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/loop/continue-while -------------------------------------------------------------------------------- /rustlabs101/operators/bitwise-op: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/operators/bitwise-op -------------------------------------------------------------------------------- /rustlabs101/operators/logical-op: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/operators/logical-op -------------------------------------------------------------------------------- /rustlabs101/scope-shadowing/scope: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/scope-shadowing/scope -------------------------------------------------------------------------------- /rustlabs101/structs/define-struct: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/structs/define-struct -------------------------------------------------------------------------------- /rustlabs101/structs/method-struct: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/structs/method-struct -------------------------------------------------------------------------------- /rustlabs101/structs/return-struct: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/structs/return-struct -------------------------------------------------------------------------------- /rustlabs101/variable/mut-variable: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/variable/mut-variable -------------------------------------------------------------------------------- /rustlabs101/Strings/String-Capcity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/Strings/String-Capcity -------------------------------------------------------------------------------- /rustlabs101/Strings/String-literal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/Strings/String-literal -------------------------------------------------------------------------------- /rustlabs101/Strings/find-substring: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/Strings/find-substring -------------------------------------------------------------------------------- /rustlabs101/Strings/slicing-string: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/Strings/slicing-string -------------------------------------------------------------------------------- /rustlabs101/data-type/bool-explicit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/data-type/bool-explicit -------------------------------------------------------------------------------- /rustlabs101/data-type/bool-implicit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/data-type/bool-implicit -------------------------------------------------------------------------------- /rustlabs101/data-type/char-explicit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/data-type/char-explicit -------------------------------------------------------------------------------- /rustlabs101/data-type/char-implicit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/data-type/char-implicit -------------------------------------------------------------------------------- /rustlabs101/data-type/define-array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/data-type/define-array -------------------------------------------------------------------------------- /rustlabs101/data-type/define-tuple: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/data-type/define-tuple -------------------------------------------------------------------------------- /rustlabs101/data-type/int-explicit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/data-type/int-explicit -------------------------------------------------------------------------------- /rustlabs101/data-type/int-implicit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/data-type/int-implicit -------------------------------------------------------------------------------- /rustlabs101/functions/multi-return: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/functions/multi-return -------------------------------------------------------------------------------- /rustlabs101/functions/pass-by-value: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/functions/pass-by-value -------------------------------------------------------------------------------- /rustlabs101/functions/return-array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/functions/return-array -------------------------------------------------------------------------------- /rustlabs101/hello-world/hello-world: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/hello-world/hello-world -------------------------------------------------------------------------------- /rustlabs101/loop/continue-for-loop: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/loop/continue-for-loop -------------------------------------------------------------------------------- /rustlabs101/operators/arithmetic-op: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/operators/arithmetic-op -------------------------------------------------------------------------------- /rustlabs101/operators/borrowing-op: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/operators/borrowing-op -------------------------------------------------------------------------------- /rustlabs101/operators/comparison-op: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/operators/comparison-op -------------------------------------------------------------------------------- /rustlabs101/variable/init-variable: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/variable/init-variable -------------------------------------------------------------------------------- /rustlabs101/variable/multi-variable: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/variable/multi-variable -------------------------------------------------------------------------------- /rustlabs101/Strings/fn-string-literal: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/Strings/fn-string-literal -------------------------------------------------------------------------------- /rustlabs101/Strings/push-single-char: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/Strings/push-single-char -------------------------------------------------------------------------------- /rustlabs101/Strings/replace-substring: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/Strings/replace-substring -------------------------------------------------------------------------------- /rustlabs101/data-type/float-explicit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/data-type/float-explicit -------------------------------------------------------------------------------- /rustlabs101/data-type/float-implicit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/data-type/float-implicit -------------------------------------------------------------------------------- /rustlabs101/functions/function-param: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/functions/function-param -------------------------------------------------------------------------------- /rustlabs101/functions/returning-value: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/functions/returning-value -------------------------------------------------------------------------------- /rustlabs101/loop/break-stat-for-loop: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/loop/break-stat-for-loop -------------------------------------------------------------------------------- /rustlabs101/operators/dereferencing-op: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/operators/dereferencing-op -------------------------------------------------------------------------------- /rustlabs101/operators/type-casting-op: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/operators/type-casting-op -------------------------------------------------------------------------------- /rustlabs101/printing-styles/eprintln: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/printing-styles/eprintln -------------------------------------------------------------------------------- /rustlabs101/scope-shadowing/shadowing: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/scope-shadowing/shadowing -------------------------------------------------------------------------------- /rustlabs101/basic-formatting/multiple-placeholders.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("{} is a {} community", "kubedaily", "Open Source "); 3 | } -------------------------------------------------------------------------------- /rustlabs101/functions/fn-array-pass-ref: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/functions/fn-array-pass-ref -------------------------------------------------------------------------------- /rustlabs101/functions/fn-array-pass-val: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/functions/fn-array-pass-val -------------------------------------------------------------------------------- /rustlabs101/functions/pass-by-reference: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/functions/pass-by-reference -------------------------------------------------------------------------------- /rustlabs101/loop/for-loop.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //define a for loop 3 | for i in 0..5 { 4 | println!("{}", i); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /rustlabs101/operators/assignment-compound-op: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RustLabs/RustLabs-Workshop/HEAD/rustlabs101/operators/assignment-compound-op -------------------------------------------------------------------------------- /rustlabs101/printing-styles/println.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | print!("Rust Programming"); 3 | print!("rustlabs"); 4 | } 5 | // prints strings to console -------------------------------------------------------------------------------- /rustlabs101/basic-formatting/debug-trailt.rs: -------------------------------------------------------------------------------- 1 | #[allow(unused_variables)] 2 | fn main() { 3 | println!("{:?}", ("This is a Rust Course", 101)); 4 | } 5 | -------------------------------------------------------------------------------- /rustlabs101/basic-formatting/placeholder-traits.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("Number : 10 \nBinary:{:b} Hexadecimal:{:x} Octal:{:o}", 10, 10, 10); 3 | } 4 | -------------------------------------------------------------------------------- /rustlabs101/data-type/char-explicit.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // explicitly define 3 | let char_1:char = 'e'; 4 | println!("character1: {}", char_1); 5 | } -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## RustLabs Workshop 2 | 3 | 4 | ## How to use this workshop 5 | 6 | ## How to contribute to this workshop 7 | 8 | ### Prerequisites 9 | 10 | -------------------------------------------------------------------------------- /rustlabs101/data-type/string-implicit.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // implicitly define 3 | let str_2 = "Rust Programming"; 4 | println!("String 2: {}", str_2); 5 | } 6 | -------------------------------------------------------------------------------- /rustlabs101/data-type/bool-explicit.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //explicitly define a bool 3 | let is_bool:bool = true; 4 | println!("explicitly_defined: {}", is_bool); 5 | } -------------------------------------------------------------------------------- /rustlabs101/operators/type-casting-op.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let a = 15; 3 | let b = (a as f64) / 2.0; 4 | println!("a: {}", a); 5 | println!("b: {}", b); 6 | } 7 | -------------------------------------------------------------------------------- /rustlabs101/variable/init-variable.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let language = "Rust"; // define a variable 3 | println!("Language: {}", language); // print the variable 4 | } 5 | -------------------------------------------------------------------------------- /rustlabs101/basic-formatting/positional-arguments.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("Enhance your coding skills from {0} . {0} labs is very {1}", "Rustlabs", "interactive"); 3 | } 4 | -------------------------------------------------------------------------------- /rustlabs101/data-type/string-explicit.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // explicitly define 3 | let str_1:&str = "Rust Programming"; 4 | println!("String 1: {}", str_1); 5 | } 6 | -------------------------------------------------------------------------------- /rustlabs101/loop/enumerate.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | for (count, variable) in (7..10).enumerate() { 3 | println!("count = {}, variable = {}", count, variable); 4 | } 5 | } -------------------------------------------------------------------------------- /rustlabs101/basic-formatting/named-arguments.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("{community} provides {kind} great content", community = "kubeDaily Community", kind = "interactive"); 3 | } -------------------------------------------------------------------------------- /rustlabs101/data-type/bool-implicit.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // assign a boolean value 3 | let a = true; 4 | let b = false; 5 | println!("a: {}", a); 6 | println!("b: {}", b); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /rustlabs101/data-type/float-implicit.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //implicitly define a float type 3 | let pi = 3.14; 4 | let e = 2.17828; 5 | println!("pi: {}", pi); 6 | println!("e: {}", e); 7 | } -------------------------------------------------------------------------------- /rustlabs101/loop/break-stat-for-loop.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // define a for loop 3 | for i in 0..10 { 4 | println!("i:{}", i); 5 | if i == 5 { 6 | break; 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /rustlabs101/data-type/len-array.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //define an array of size 4 3 | let arr:[i32;4] = [1, 2, 3, 4]; 4 | // print the length of array 5 | println!("Length of array: {}", arr.len()); 6 | } -------------------------------------------------------------------------------- /rustlabs101/data-type/float-explicit.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //explicitly define a float type 3 | let f1:f32 = 32.9; 4 | let f2:f64 = 6789.89; 5 | println!("f1: {}", f1); 6 | println!("f2: {}", f2); 7 | } 8 | -------------------------------------------------------------------------------- /rustlabs101/data-type/char-implicit.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // implicitly define 3 | let char_2 = 'a'; 4 | let char_3 = 'b'; 5 | println!("character2: {}", char_2); 6 | println!("character3: {}", char_3); 7 | } -------------------------------------------------------------------------------- /rustlabs101/variable/multi-variable.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let (course,category) =("Rust","beginner"); // assign multiple values 3 | println!("This is a {} 101 track of {}.", category, course); // print the value 4 | } 5 | -------------------------------------------------------------------------------- /rustlabs101/data-type/print-tuple.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //define a tuple 3 | let person_data = ("Alex", 48, "35kg", "6ft"); 4 | //print the value of tuple 5 | println!("Tuple - Person Data : {:?}",person_data); 6 | } 7 | -------------------------------------------------------------------------------- /rustlabs101/loop/loop.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //define an integer variable 3 | let mut var = 1; 4 | // define a while loop 5 | loop { 6 | var = var + 1; 7 | println!("{}", var); 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /rustlabs101/Strings/slicing-string.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let string = "Rust Programming".to_string(); 3 | let slice = &string[5..12]; 4 | // get characters at 5,6,7,8,9,10 and 11 indexes 5 | println!("Slice : {}", slice); 6 | } 7 | -------------------------------------------------------------------------------- /rustlabs101/data-type/print-array.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //define an array of size 4 3 | let arr:[i32;4] = [1, 2, 3, 4]; 4 | //Using debug trait 5 | println!("\nPrint using a debug trait"); 6 | println!("Array: {:?}", arr); 7 | } 8 | -------------------------------------------------------------------------------- /rustlabs101/loop/break-stat-loop.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let mut i = 1; 3 | // define a loop 4 | loop{ 5 | println!("i:{}", i); 6 | if i == 5 { 7 | break; 8 | } 9 | i = i + 1; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /rustlabs101/operators/logical-op.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let a = true; 3 | let b = false; 4 | println!("Operand 1:{}, Operand 2:{}", a , b); 5 | println!("AND:{}", a && b); 6 | println!("OR:{}", a || b); 7 | println!("NOT:{}", ! a); 8 | } -------------------------------------------------------------------------------- /rustlabs101/Strings/push-string.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // define a string object 3 | let mut course = String::from("Rust"); 4 | // push a string 5 | course.push_str(" Programming"); 6 | println!("This is a beginner course in {}.", course); 7 | } -------------------------------------------------------------------------------- /rustlabs101/printing-styles/eprintln.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | eprintln!("Rust Programming"); 3 | eprintln!("Rustlabs 101"); 4 | } 5 | //📝Note: eprint!() and eprintln!() come in handy when we want to indicate to the user that an error condition has occurred. -------------------------------------------------------------------------------- /rustlabs101/Strings/push-single-char.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // define a String object 3 | let mut course = String::from("Rus"); 4 | // push a character 5 | course.push('t'); 6 | println!("This is a beginner course in {}.", course); 7 | } 8 | -------------------------------------------------------------------------------- /rustlabs101/loop/nested-loop.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | for i in 1..5{ //outer loop 3 | println!("Multiplication Table of : {}", i); 4 | for j in 1..5 { // inner loop 5 | println!("{} * {} = {}", i, j, i * j); 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /rustlabs101/Strings/trim-string.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let string = " Rust Programming ".to_string(); 3 | let trim_string = string.trim(); 4 | // get characters at 5,6,7,8,9,10 and 11 indexes 5 | println!("Trimmed_string : {}", trim_string); 6 | } -------------------------------------------------------------------------------- /rustlabs101/Strings/String-Capcity.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // define a growable string variable 3 | let course = String::from("Rust"); 4 | println!("This is a beginner course in {}.", course); 5 | //capacity in bytes 6 | println!("Capacity: {}.", course.capacity()); 7 | } -------------------------------------------------------------------------------- /rustlabs101/data-type/mut-array.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //define a mutable array of size 4 3 | let mut arr:[i32;4] = [1, 2, 3, 4]; 4 | println!("The value of array at index 1: {}", arr[1]); 5 | arr[1] = 9; 6 | println!("The value of array at index 1: {}", arr[1]); 7 | } 8 | -------------------------------------------------------------------------------- /rustlabs101/functions/define-fn.rs: -------------------------------------------------------------------------------- 1 | //define a function 2 | fn display_message(){ 3 | println!("Hi, this is my user defined function"); 4 | } 5 | //driver function 6 | fn main() { 7 | //invoke a function 8 | display_message(); 9 | println!("Function ended"); 10 | } 11 | -------------------------------------------------------------------------------- /rustlabs101/Strings/fn-string-obj.rs: -------------------------------------------------------------------------------- 1 | fn main(){ 2 | let course:String = String::from("Rust Programming"); 3 | display_course_name(course); 4 | //cannot access course after display 5 | } 6 | fn display_course_name(my_course:String){ 7 | println!("Course : {}", my_course); 8 | } 9 | -------------------------------------------------------------------------------- /rustlabs101/loop/break-stat-while.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let mut i = 1; 3 | let found = false; 4 | // define a while loop 5 | while !found { 6 | println!("i:{}", i); 7 | if i == 5 { 8 | break; 9 | } 10 | i = i + 1; 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /rustlabs101/variable/mut-variable.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let mut language = "Rust"; // define a mutable variable 3 | println!("Language: {}", language); // print the variable 4 | language = "Java"; // update the variable 5 | println!("Language: {}", language); // print the updated value of variable 6 | } 7 | -------------------------------------------------------------------------------- /rustlabs101/Strings/fn-string-literal.rs: -------------------------------------------------------------------------------- 1 | fn main(){ 2 | let course: &str = "Rust Programming"; 3 | display_course_name(course); 4 | println!("{}",course); // string literal is used after the function call 5 | } 6 | fn display_course_name(my_course: &str){ 7 | println!("Course : {}", my_course); 8 | } 9 | -------------------------------------------------------------------------------- /rustlabs101/Strings/String-literal.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //define a primitive String variable 3 | let language:&str = "Rust"; 4 | //print the String literal 5 | println!("String literal: {}", language); 6 | //print the length of the String literal 7 | println!("Length of the string literal: {}", language.len()); 8 | } 9 | -------------------------------------------------------------------------------- /rustlabs101/functions/fn-array-pass-ref.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let mut arr = [1, 2, 3, 4, 5]; 3 | modify_my_array(&mut arr); 4 | println!("Array in Driver Function : {:?}", arr); 5 | } 6 | fn modify_my_array(arr:&mut [i32;5]){ 7 | arr[2] = 8; 8 | arr[3] = 9; 9 | println!("Array in my Function : {:?}", arr); 10 | } 11 | -------------------------------------------------------------------------------- /rustlabs101/data-type/int-implicit.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //explicitly define an integer 3 | let a = 21; 4 | let b = 1; 5 | let c = 54; 6 | let d = 343434; 7 | //print the variable 8 | println!("a: {}", a); 9 | println!("b: {}", b); 10 | println!("c: {}", c); 11 | println!("d: {}", d); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /rustlabs101/data-type/int-explicit.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //explicitly define an integer 3 | let a:i32 = 24; 4 | let b:u64 = 23; 5 | let c:usize = 26; 6 | let d:isize = 29; 7 | //print the values 8 | println!("a: {}", a); 9 | println!("b: {}", b); 10 | println!("c: {}", c); 11 | println!("d: {}", d); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /rustlabs101/loop/continue-for-loop.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // define a for loop 3 | for var in 0..10 { 4 | if var == 4 { 5 | println!("I encoutered a continue statement"); 6 | continue; 7 | } 8 | println!("var: {}", var); 9 | println!("I did not encounter continue statement"); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /rustlabs101/Strings/Concatenat.rs: -------------------------------------------------------------------------------- 1 | #[allow(unused_variables, unused_mut)] 2 | fn main(){ 3 | // define a String object 4 | let course = "Rust".to_string(); 5 | // define a String object 6 | let course_type = " beginner course".to_string(); 7 | // concatenate using the + operator 8 | let result = course + &course_type; 9 | println!("{}", result); 10 | } -------------------------------------------------------------------------------- /rustlabs101/functions/return-array.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let arr = [1, 2, 3, 4, 5]; 3 | modify_my_array(arr); 4 | println!("Array in Driver Function : {:?}", arr); 5 | println!("Array after Function Call : {:?}", modify_my_array(arr)); 6 | } 7 | fn modify_my_array(mut arr:[i32;5])->[i32;5]{ 8 | arr[2] = 8; 9 | arr[3] = 9; 10 | arr 11 | } 12 | -------------------------------------------------------------------------------- /rustlabs101/operators/arithmetic-op.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let a = 4; 3 | let b = 3; 4 | 5 | println!("Operand 1:{}, Operand 2:{}", a , b); 6 | println!("Addition:{}", a + b); 7 | println!("Subtraction:{}", a - b); 8 | println!("Multiplication:{}", a * b); 9 | println!("Division:{}", a / b); 10 | println!("Modulus:{}", a % b); 11 | } 12 | -------------------------------------------------------------------------------- /rustlabs101/Strings/find-substring.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // define a growable string variable 3 | let str = String::from("Rust Programming"); 4 | let sub_str = String::from("Rust"); 5 | println!("This is a beginner course in {}.", str); 6 | // find if string contains a substring 7 | println!("{} is a substring of {}: {}.", sub_str, str, str.contains("Rust")); 8 | } -------------------------------------------------------------------------------- /rustlabs101/functions/pass-by-value.rs: -------------------------------------------------------------------------------- 1 | fn square(mut n:i32){ 2 | n = n * n; 3 | println!("The value of n inside function : {}", n); 4 | } 5 | fn main() { 6 | let n = 4; 7 | println!("The value of n before function call : {}", n); 8 | println!("Invoke Function"); 9 | square(n); 10 | println!("\nThe value of n after function call : {}", n); 11 | } -------------------------------------------------------------------------------- /rustlabs101/operators/comparison-op.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let a = 2; 3 | let b = 3; 4 | println!("Operand 1:{}, Operand 2:{}", a , b); 5 | println!("a > b:{}", a > b); 6 | println!("a < b:{}", a < b); 7 | println!("a >= b:{}", a >= b); 8 | println!("a <= b:{}", a <= b); 9 | println!("a == b:{}", a == b); 10 | println!("a != b:{}", a != b); 11 | } -------------------------------------------------------------------------------- /rustlabs101/Strings/replace-substring.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // define a growable string variable 3 | let str = String::from("Rust Programming"); 4 | let replace_from = "Programming"; 5 | let replace_to = "Language"; 6 | // find if string contains a substring 7 | let result = str.replace(replace_from, replace_to); 8 | println!("{} now becomes {}.", str, result); 9 | } -------------------------------------------------------------------------------- /rustlabs101/operators/bitwise-op.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let a = 5; 3 | let b = 6; 4 | println!("Operand 1: {}, Operand 2: {}", a , b); 5 | println!("AND: {}", a & b); 6 | println!("OR: {}", a | b); 7 | println!("XOR: {}", a ^ b); 8 | println!("NOT a: {}", !a); 9 | println!("Left shift: {}", a << 2); 10 | println!("Right shift: {}", a >> 1); 11 | 12 | } -------------------------------------------------------------------------------- /rustlabs101/data-type/get-slice.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //define an array of size 4 3 | let arr:[i32;4] = [1, 2, 3, 4]; 4 | //define the slice 5 | let slice_array1:&[i32] = &arr; 6 | let slice_array2:&[i32] = &arr[0..2]; 7 | // print the slice of an array 8 | println!("Slice of an array: {:?}", slice_array1); 9 | println!("Slice of an array: {:?}", slice_array2); 10 | } -------------------------------------------------------------------------------- /rustlabs101/functions/pass-by-reference.rs: -------------------------------------------------------------------------------- 1 | fn square(n:&mut i32){ 2 | *n = *n * *n; 3 | println!("The value of n inside function : {}", n); 4 | } 5 | fn main() { 6 | let mut n = 4; 7 | println!("The value of n before function call : {}", n); 8 | println!("Invoke Function"); 9 | square(&mut n); 10 | println!("The value of n after function call : {}", n); 11 | } -------------------------------------------------------------------------------- /rustlabs101/operators/dereferencing-op.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //mutable reference to a variable 3 | let mut x = 10; 4 | println!("Value of x:{}", x); 5 | let a = & mut x; 6 | println!("Value of a:{}", a); 7 | //dereference a variable 8 | *a = 11; 9 | println!("Value of a:{}", a); 10 | println!("Value of x:{}", x); // Note that value of x is updated 11 | } 12 | 13 | -------------------------------------------------------------------------------- /rustlabs101/Strings/format-micro.rs: -------------------------------------------------------------------------------- 1 | fn main(){ 2 | 3 | let course = "Rust".to_string(); 4 | let _course_type = "beginner course".to_string(); 5 | // default format macro 6 | let _result = format!("{} {}", course, _course_type); 7 | // passing value in the placeholder in the format macro 8 | let _result = format!("{0} {1}", course,_course_type); 9 | println!("{}", _result); 10 | } -------------------------------------------------------------------------------- /rustlabs101/data-type/define-array.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //define an array of size 4 3 | let arr:[i32;4] = [1, 2, 3, 4]; 4 | //print the first element of array 5 | println!("The first value of array is {}", arr[0]); 6 | // initialize an array of size 4 with 0 7 | let arr1 = [0; 4]; 8 | //print the first element of array 9 | println!("The first value of array is {}", arr1[0]); 10 | } 11 | -------------------------------------------------------------------------------- /rustlabs101/loop/continue-loop.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // define an integer variable 3 | let mut var = 1; 4 | // define a loop 5 | loop { 6 | var = var + 1; 7 | println!("{}", var); 8 | 9 | if var == 4 { 10 | println!("I encoutered continue statement"); 11 | continue; 12 | } 13 | println!("I did not encounter continue statement"); 14 | } 15 | } -------------------------------------------------------------------------------- /rustlabs101/loop/loop-label.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | 'outer:for i in 1..5 { //outer loop 3 | println!("Muliplication Table : {}", i); 4 | 'inner:for j in 1..5 { // inner loop 5 | if i == 3 { continue 'outer; } // Continues the loop over `i`. 6 | if j == 2 { continue 'inner; } // Continues the loop over `j`. 7 | println!("{} * {} = {}", i, j, i * j); 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /rustlabs101/scope-shadowing/shadowing.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let outer_variable = 112; 3 | { // start of code block 4 | let inner_variable = 213; 5 | println!("block variable: {}", inner_variable); 6 | let outer_variable = 117; 7 | println!("block variable outer: {}", outer_variable); 8 | } // end of code block 9 | println!("outer variable: {}", outer_variable); 10 | } -------------------------------------------------------------------------------- /rustlabs101/functions/function-param.rs: -------------------------------------------------------------------------------- 1 | //function definition 2 | fn my_func(param_1:i32, param_2:i32) { 3 | println!("The first value passed inside function : {}", param_1); 4 | println!("The second value passed inside function : {}", param_2); 5 | } 6 | fn main() { 7 | let value_1 = 1; 8 | let value_2 = 2; 9 | //calling the function 10 | my_func( value_1, value_2 ); 11 | println!("Function ended"); 12 | } 13 | -------------------------------------------------------------------------------- /rustlabs101/operators/assignment-compound-op.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //define a mutable variable 3 | let mut a = 2; 4 | println!("a:{}", a); 5 | a += 1; 6 | println!("a+=1:{}", a); 7 | println!("a:{}", a); 8 | a -= 1; 9 | println!("a-=1:{}", a); 10 | println!("a:{}", a); 11 | a /= 1; 12 | println!("a/=1:{}", a); 13 | println!("a:{}", a); 14 | a *= 3; 15 | println!("a/=3:{}", a); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /rustlabs101/data-type/mut-tuple.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //define a tuple 3 | let mut person_data = ("Alex", 48, "35kg", "6ft"); 4 | //print the value of tuple 5 | println!("The value of the tuple at index 0 and index 1 are {} {}", person_data.0, person_data.1); 6 | //modify the value at index 0 7 | person_data.0 = "John"; 8 | //print the modified value 9 | println!("The value of the tuple at index 0 and index 1 are {} {}", person_data.0, person_data.1); 10 | } -------------------------------------------------------------------------------- /rustlabs101/loop/while.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let mut var = 1; //define an integer variable 3 | let mut found = false; // define a boolean variable 4 | // define a while loop 5 | while !found { 6 | var=var+1; 7 | //print the variable 8 | println!("{}", var); 9 | // if the modulus of variable is 1 then found is equal to true 10 | if var % 3 == 1 { 11 | found = true; 12 | } 13 | println!("Loop runs"); 14 | } 15 | } -------------------------------------------------------------------------------- /rustlabs101/operators/borrowing-op.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let x = 10; 3 | let mut y = 13; 4 | //immutable reference to a variable 5 | let a = &x; 6 | println!("Value of a:{}", a); 7 | println!("Value of x:{}", x); // x value remains the same since it is immutably borrowed 8 | //mutable reference to a variable 9 | let b = &mut y; 10 | 11 | println!("Value of b:{}", b); 12 | println!("Value of y:{}", y); 13 | // y value is changed since it is mutably borrowed 14 | let y = 2; 15 | println!("Value of y:{}", y); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /rustlabs101/loop/continue-while.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // define an integer variable 3 | let mut var = 1; 4 | // define a boolean variable 5 | let mut found = false; 6 | // define a while loop 7 | while !found { 8 | var = var + 1; 9 | println!("{}", var); 10 | 11 | if var == 4 { 12 | println!("I encoutered a continue statement"); 13 | continue; 14 | } 15 | println!("I did not encounter continue statement"); 16 | 17 | if var == 10{ 18 | found = true; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /rustlabs101/data-type/define-tuple.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | //define a tuple 3 | let person_data = ("Alex", 48, "35kg", "6ft"); 4 | // access value of a tuple 5 | println!("The value of the tuple at index 0 and index 1 are {} {}",person_data.0,person_data.1); 6 | 7 | //define a tuple 8 | let person_data = ("Alex", 48, "35kg", "6ft"); 9 | // get individual values out of tuple 10 | let (w ,x, y, z) = person_data; 11 | //print values 12 | println!("Name : {}",w); 13 | println!("Age : {}",x); 14 | println!("Weight : {}",y); 15 | println!("Height : {}",z); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /rustlabs101/functions/multi-return.rs: -------------------------------------------------------------------------------- 1 | // driver function 2 | fn main() { 3 | let length = 4; 4 | let width = 3; 5 | println!("Rectangle lenth:{}", length); 6 | println!("Rectangle width:{}", width); 7 | let (area, perimeter) = calculate_area_perimeter(length, width); 8 | println!("Area: {}, Perimeter: {}", area, perimeter); 9 | } 10 | // calculate area and perimeter 11 | fn calculate_area_perimeter(x: i32, y: i32) -> (i32, i32) { 12 | // calculate the area and perimeter of rectangle 13 | let area = x * y; 14 | let perimeter = 2 * (x + y); 15 | // return the area and perimeter of rectangle 16 | (area, perimeter) 17 | } 18 | 19 | -------------------------------------------------------------------------------- /rustlabs101/structs/fn-struct.rs: -------------------------------------------------------------------------------- 1 | //declare a struct 2 | struct Course { 3 | code:i32, 4 | name:String, 5 | level:String, 6 | } 7 | fn display_mycourse_info(c:Course) { 8 | println!("Name:{}, Level:{} ,code: {}", c .name, c .level, c.code); 9 | } 10 | fn main() { 11 | //initialize 12 | let course1 = Course { 13 | name:String::from("Rust"), 14 | level:String::from("beginner"), 15 | code:130 16 | }; 17 | display_mycourse_info(course1); 18 | let course2 = Course { 19 | name:String::from("Java"), 20 | level:String::from("beginner"), 21 | code:130 22 | }; 23 | display_mycourse_info(course2); 24 | } 25 | -------------------------------------------------------------------------------- /rustlabs101/functions/fn-array-pass-val.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let arr = [1, 2, 3, 4, 5]; 3 | modify_my_array(arr); 4 | println!("Array in Driver Function : {:?}", arr); 5 | } 6 | fn modify_my_array(mut arr:[i32;5]){ 7 | arr[2] = 8; 8 | arr[3] = 9; 9 | println!("Array in my Function : {:?}", arr); 10 | } 11 | 12 | 13 | // fn main() { 14 | // let arr = [1, 2, 3, 4, 5]; 15 | // println!("Array in Driver Function : {:?}", arr); 16 | // calculate_mean(arr); 17 | // } 18 | // fn calculate_mean(arr:[i32;5]){ 19 | // let mut sum = 0; 20 | // for i in 0..5 { 21 | // sum += arr[i]; 22 | // } 23 | // println!("Mean of array values: {}", sum/5); 24 | // } 25 | -------------------------------------------------------------------------------- /rustlabs101/structs/method-struct.rs: -------------------------------------------------------------------------------- 1 | //declare a struct 2 | 3 | struct Course { 4 | 5 | name: String, 6 | 7 | level: String, 8 | 9 | code:i32 10 | 11 | } 12 | 13 | //impl construct to define struct methods 14 | 15 | impl Course { 16 | 17 | fn name_code(&self) -> String { 18 | 19 | format!("{} {}", self.name, self.code) 20 | 21 | } 22 | 23 | } 24 | 25 | 26 | 27 | fn main() { 28 | 29 | let course_1 = Course { 30 | 31 | name: "Rust".to_string(), 32 | 33 | level:"beginner".to_string(), 34 | 35 | code:132 36 | 37 | }; 38 | 39 | //call the non-static method 40 | 41 | println!("This is a {} course: {}", course_1.level, course_1.name_code()); 42 | 43 | } 44 | 45 | -------------------------------------------------------------------------------- /rustlabs101/functions/returning-value.rs: -------------------------------------------------------------------------------- 1 | fn square(n:i32)->i32{ 2 | println!("The value of n inside function : {}", n); 3 | let m = n * n; 4 | m // return the square of the number n 5 | } 6 | fn main() { 7 | let n = 4; 8 | println!("The value of n before function call : {}", n); 9 | println!("Invoke Function"); 10 | println!("\nOutput : {}",square(n)); 11 | } 12 | 13 | //fn square(n:i32)->i32{ 14 | // println!("The value of n inside function : {}", n); 15 | // return n * n; 16 | // } 17 | // fn main() { 18 | // let n = 4; 19 | // println!("The value of n before function call : {}", n); 20 | // println!("Invoke Function"); 21 | // println!("\nOutput : {}", square(n)); 22 | // } 23 | 24 | -------------------------------------------------------------------------------- /rustlabs101/scope-shadowing/scope.rs: -------------------------------------------------------------------------------- 1 | // fn main() { 2 | // let outer_variable = 112; 3 | // { // start of code block 4 | // let inner_variable = 213; 5 | // println!("block variable inner: {}", inner_variable); 6 | // println!("block variable outer: {}", outer_variable); 7 | // } // end of code block 8 | // println!("inner variable: {}", inner_variable); // use of inner_variable outside scope 9 | // } 10 | 11 | 12 | fn main() { 13 | let outer_variable = 112; 14 | let inner_variable = 213; 15 | { // start of code block 16 | println!("block variable inner: {}", inner_variable); 17 | println!("block variable outer: {}", outer_variable); 18 | } // end of code block 19 | println!("inner variable: {}", inner_variable); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /rustlabs101/structs/define-struct.rs: -------------------------------------------------------------------------------- 1 | //declare a struct 2 | struct Course { 3 | code:i32, 4 | name:String, 5 | level:String, 6 | } 7 | 8 | fn main() { 9 | //initialize 10 | let mut course1 = Course { 11 | name:String::from("Rust"), 12 | level:String::from("beginner"), 13 | code:130, 14 | }; 15 | let course2 = Course { 16 | name:String::from("Javascript"), 17 | level:String::from("beginner"), 18 | code:122, 19 | }; 20 | //access 21 | println!("Name:{}, Level:{}, code: {}", course1.name, course1.level, course1.code); 22 | println!("Name:{}, Level:{}, code: {}", course2.name, course2.level, course2.code); 23 | //update 24 | course1.name = "Java".to_string(); 25 | course1.code = 134; 26 | println!("Name:{}, Level:{} ,code: {}", course1.name, course1.level, course1.code); 27 | } 28 | -------------------------------------------------------------------------------- /rustlabs101/structs/return-struct.rs: -------------------------------------------------------------------------------- 1 | //declare a struct 2 | struct Course { 3 | code:i32, 4 | name:String, 5 | level:String, 6 | } 7 | fn return_rust_course_info(c1:Course, c2:Course)-> Course{ 8 | println!("I got into function and return values from there"); 9 | if c1.name == "Rust" { 10 | return c1; 11 | } 12 | else{ 13 | return c2; 14 | } 15 | } 16 | 17 | fn main() { 18 | //initialize 19 | let course1 = Course { 20 | name:String::from("Rust"), 21 | level:String::from("beginner"), 22 | code:130 23 | }; 24 | let course2 = Course { 25 | name:String::from("Java"), 26 | level:String::from("beginner"), 27 | code:130 28 | }; 29 | 30 | let choose_course = return_rust_course_info(course1, course2); 31 | println!("I choose to learn {} {} course with code:{}", choose_course.name, choose_course.level, choose_course.code); 32 | } -------------------------------------------------------------------------------- /rustlabs101/Strings/String-obj.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // create an empty String 3 | let course1 = String::new(); 4 | // convert String literal to String object using .to_string 5 | let s_course1 = course1.to_string(); 6 | // print the String object 7 | println!("This is an empty string {}.", s_course1); 8 | // print the length of an empty String object 9 | println!("This is a length of my empty string {}.", s_course1.len()); 10 | 11 | // create a String literal 12 | let course2 = "Rust Programming"; 13 | // convert String literal to string object using .to_string 14 | let s_course2 = course2.to_string(); 15 | // print the String object 16 | println!("This is a string literal : {}.", s_course2); 17 | // print the length of a String object 18 | println!("This is a length of my string literal {}.", s_course2.len()); 19 | 20 | // define a String object using from method 21 | let course3 = String::from("Rust Language"); 22 | // print the String object 23 | println!("This is a string object : {}.", course3); 24 | // print the length of an string object 25 | println!("This is the length of my string object {}.", course3.len()); 26 | } 27 | --------------------------------------------------------------------------------