diff --git a/.gitignore b/.gitignore index 6df2f06..58bcaa2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /target +/**/target/ -/*/target \ No newline at end of file +/*/target/ \ No newline at end of file diff --git a/branches/Cargo.lock b/branches/Cargo.lock new file mode 100644 index 0000000..c5d0014 --- /dev/null +++ b/branches/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "branches" +version = "0.1.0" diff --git a/branches/Cargo.toml b/branches/Cargo.toml new file mode 100644 index 0000000..6596455 --- /dev/null +++ b/branches/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "branches" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/branches/src/main.rs b/branches/src/main.rs new file mode 100644 index 0000000..c75afa4 --- /dev/null +++ b/branches/src/main.rs @@ -0,0 +1,30 @@ +fn main() { + // comments go above line attempting to comment + println!("Hello, world!"); + example_funct(); +} + +// implicitly implied that a unit type is returned but neat to know it is allowed +fn example_funct () -> () { + let number = 1; + // allowed bool statement + let run_if = number == 0; + // each if is a different arm or branch of the code path, will not check any other files once the first one is true + // must be a bool, rust will not accept if number or etc, must be converted into bool + if number != 0 { + println!("Number is non-zero") + // multiple ifs in a row + } else if run_if { + println!("Number is zero") + // in the ase that all are flase + } else { + println!("Number is not real") + } + + let condition = true; + // ifs can also be part of a statement to set a value depending on another value + let another_number = if condition { 7 } else { 0 }; +} + +// too many ifs or if elses can clutter code, use the match case instead +// 5 ifs should mean the code needs to be refactored \ No newline at end of file diff --git a/functions_rust/src/main.rs b/functions_rust/src/main.rs index dd972e4..5b621e6 100644 --- a/functions_rust/src/main.rs +++ b/functions_rust/src/main.rs @@ -41,7 +41,7 @@ fn example_function (x:i8, y:u16) { // EXPRESSIONS DO NOT END WITH ; // if you add a ; to the end of a statment it will turn into a statement and not return anything // unless it is a return keyword -// or if it is a marco +// or if it is a marco (not required) fn with_return_plus_one (c: i16) -> i16 {