diff --git a/array_access/Cargo.toml b/array_access/Cargo.toml new file mode 100644 index 0000000..5378f9b --- /dev/null +++ b/array_access/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "array_access" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/array_access/src/main.rs b/array_access/src/main.rs new file mode 100644 index 0000000..0aa3f68 --- /dev/null +++ b/array_access/src/main.rs @@ -0,0 +1,18 @@ +use std::io; + +fn main() { + let a = [1, 2, 3, 4, 5]; + let mut index = String::new(); + io::stdin() + .read_line(&mut index) + .expect("doh"); + let index: usize = index + .trim() + .parse() + .expect("notta num"); + + let element = a[index]; + + println!("you gotta {element}"); + +} diff --git a/notes b/notes new file mode 100644 index 0000000..4c39058 --- /dev/null +++ b/notes @@ -0,0 +1,83 @@ +const is a thing +const convention is all upper with _ +const evaluation info: https://doc.rust-lang.org/reference/const_eval.html + +you can add arbitray scopes to modify local variables or for other purposes! + { + some random shit; + } + +https://doc.rust-lang.org/book/ch03-02-data-types.html + +scalars: + ints + floats + bools + chars +integer types: + 8-bit i8 u8 + 16-bit i16 u16 + 32-bit i32 u32 + 64-bit i64 u64 + 128-bit i128 u128 + arch isize usize + +number literals +decimal 1_024 +hex 0xff +oct 0o77 +binary 0b1100_1011_0100_0001 +byte b'E' + +release builds have no overflow wrap checking +don't rely on this behavior + +explicitly use +`wrapping_*` methods to do this + such as wrapping_add +Return the None value if there is overflow with the checked_* methods +Return the value and a boolean indicating whether there was overflow with the overflowing_* methods + +wtf is this: + Saturate at the value’s minimum or maximum values with saturating_* methods + +there are f32 and f64 floats. f64 is default cause they are about the same speed + +normal math operators +int division is floor +remainder % exists + +all operators: +https://doc.rust-lang.org/book/appendix-02-operators.html + + +type annotation: + +let var: type = val; + +Rust’s char type is four bytes in size and represents a Unicode Scalar Value + +Compound types + + primitive compound types: + tuples + arrays + +Tuples: + fixed length combo of types + type is () + + pulling out the elements of a tuple into individual variables is called destructuring + +Arrays: + fixed type fixed length + [] + + init: + let a: [1, 2, 3]; + let a: [3, 0]; // set every element to same value + reference: + let first = a[0]; + they are allocated on stack + + diff --git a/tuple1/Cargo.toml b/tuple1/Cargo.toml new file mode 100644 index 0000000..d63cf88 --- /dev/null +++ b/tuple1/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "tuple1" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/tuple1/src/main.rs b/tuple1/src/main.rs new file mode 100644 index 0000000..03f583e --- /dev/null +++ b/tuple1/src/main.rs @@ -0,0 +1,6 @@ +fn main() { + let x: (i32, f64, u8) = (500, 6.4, 1); + let _five_hundred = x.0; + let _six_point_four = x.1; + let _one = x.2; +} diff --git a/win_oops b/win_oops new file mode 100644 index 0000000..fc2172a --- /dev/null +++ b/win_oops @@ -0,0 +1,23 @@ +12/13/2022 05:09 AM